Hello everybody
Hello, I am trying to create a class based on an example from the B4X manual.
I manage to create the decodleds class but I have difficulties to initialize the class or the qrt2 variable, the main program does not see qrt2 of decodleds. Can we initialize variables in the class, for example the imageview?
The goal of the program is to change the value of qrt2 (click on 1 button for example) then the decodleds class retrieves qrt2 and displays the 4 good images representing a quartet of leds according to the value of qrt2.
I don't understand why B4A is asking me for an "array" ?
Is there a simple example for creating a class?
Here is the source code
Thank you beforehand.
Hello, I am trying to create a class based on an example from the B4X manual.
I manage to create the decodleds class but I have difficulties to initialize the class or the qrt2 variable, the main program does not see qrt2 of decodleds. Can we initialize variables in the class, for example the imageview?
The goal of the program is to change the value of qrt2 (click on 1 button for example) then the decodleds class retrieves qrt2 and displays the 4 good images representing a quartet of leds according to the value of qrt2.
I don't understand why B4A is asking me for an "array" ?
Is there a simple example for creating a class?
Here is the source code
Thank you beforehand.
classe decodleds:
Sub Class_Globals
Private led5,led6,led7,led8 As ImageView
Private qrt2 As Byte
End Sub
'Sub Process_Globals
' 'These global variables will be declared once when the application starts.
' 'These variables can be accessed from all modules.
'
' Public QRT2 As Byte
'
'
'End Sub
'Initializes the object. You can add parameters To this method If needed.
Sub Initialize
qrt2 = 0
End Sub
public Sub quartet2 As Byte
'Dim ImageWiew1, ImageWiev2, ImageWiev3, ImageWiev4)
'Dim led5,led6,led7,led8 As ImageView
If qrt2 = 0 Then
'******************************** 0 *************************************
led5.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
led6.Bitmap = LoadBitmap(File.DirAssets, "led_vert.png")
led7.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
led8.Bitmap = LoadBitmap(File.DirAssets, "led_vert.png")
End If
If qrt2 = 2 Then
'******************************** 0 *************************************
led5.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
led6.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
led7.Bitmap = LoadBitmap(File.DirAssets, "led_vert.png")
led8.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
End If
If qrt2 = 4 Then
'******************************** 0 *************************************
led5.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
led6.Bitmap = LoadBitmap(File.DirAssets, "led_vert.png")
led7.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
led8.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
End If
End Sub
main program:
#Region Project Attributes
#ApplicationLabel: nixie counter
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: true
#IncludeTitle: false
#End Region
'Activity module
Sub Process_Globals
Public QRT1 As Byte
' Public QRT2 As Byte
Public BV1 As Byte
Public BV2 As Byte
End Sub
Sub Globals
Private pnl1 As Panel
Private cvsGraph As Canvas
Private Label1 As Label
Private ImageView1 As ImageView
Private ImageView2 As ImageView
Private ImageView3 As ImageView
Private ImageView4 As ImageView
Private Lbll6 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main") ' load the layout
cvsGraph.Initialize(pnl1) ' initialize the Canvas for the panel
Dim Deco As decodleds
'Deco.initialize(0, 0)
pnl1.Invalidate
'set zeros
End Sub
Sub quartet1
If QRT1 = 3 Then
'******************************** 0 *************************************
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "led_vert.png")
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "led_vert.png")
End If
If QRT1 = 1 Then
'******************************** 1 *************************************
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "led_vert.png")
End If
If QRT1 = 2 Then
'******************************** 2 *************************************
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "led_vert.png")
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "led_off.png")
End If
End Sub
Sub btunit_Click (Deco As decodleds) As Byte
BV1 = BV1 + 1
QRT1=Bit.And(0x0F,BV1)
quartet1
BV2 = BV1/16
qrt2 = Bit.And(0x0F, BV2)
Deco.quartet2(qrt2)
' Deco.quartet2(QRT2)
' D.initialise (QRT2)
Lbll6.Text = BV1
Label1.Text = "+++"
End Sub
Sub btdiz_Click
BV1 = 0
QRT1 = 0
' QRT2 = 0
quartet1
Lbll6.Text = BV1
Label1.Text = "ZZERO"
End Sub
Sub btcent_Click
BV1 = BV1 - 1
QRT1=Bit.And(0x0F,BV1)
quartet1
BV2 = BV1/16
' QRT2 = Bit.And(0x0F, BV2)
Label1.Text = "---"
If BV1 > 15 Then
Label1.Text = "33ces"
End If
Lbll6.Text = BV1
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub