Hi all,
this question refers both to B4A and B4J languages,
I apologize for any errors, but English is not my native language.
I used several times classes with B4A and B4J making my code portable between various projects.
Now I need to use subclasses (or any other) inside classes and do not know if this can be done in any way.
Let me explain ...
For example, if I create a class with B4J or B4A simulating Arduino (let's call it ArduinoClass)
I use the class like this:
Then in the Main module I write this:
Up to this point everything is ok, but now I have 2 questions that I can't find answer reading the forum:
QUESTION 1
How would I write a nested class within another class?
What I need to do in the Main is something like this:
where Serial should be a subclass of the class ArduinoClass and contain 3 methods (in this example, begin, print and println)
QUESTION 2
How would I write a class that can concatenate several commands how StringBuilder does where for example we can have this :
Then it would be possible to do something like this?
Thank you very much to anyone who will get out of these doubts from my mind.
this question refers both to B4A and B4J languages,
I apologize for any errors, but English is not my native language.
I used several times classes with B4A and B4J making my code portable between various projects.
Now I need to use subclasses (or any other) inside classes and do not know if this can be done in any way.
Let me explain ...
For example, if I create a class with B4J or B4A simulating Arduino (let's call it ArduinoClass)
I use the class like this:
B4X:
Sub Class_Globals
' Private and Public variables
Public const OUTPUT As Byte = 0
Public const INPUT As Byte = 1
Public const INPUT_PULLUP As Byte = 2
Public const LOW As Byte = 0
Public const HIGH As Byte = 1
End Sub
'Initializes the Arduino object. You can add parameters to this method if needed.
Public Sub Initialize()
' write here some initializations
End Sub
Public Sub pinMode(Pin As Byte, Value As Byte)
' write here some code for pinMode command
End Sub
Public Sub digitalWrite(Pin As Byte, Value As Byte)
' write here some code for digitalWrite command
End Sub
Then in the Main module I write this:
B4X:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim Arduino As ArduinoClass
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
Arduino.Initialize()
Arduino.pinMode(13, Arduino.OUTPUT)
Arduino.digitalWrite(13, HIGH)
End Sub
QUESTION 1
How would I write a nested class within another class?
What I need to do in the Main is something like this:
B4X:
Arduino.Serial.begin(115200)
Arduino.Serial.print("Hello")
Arduino.Serial.println("Hello")
QUESTION 2
How would I write a class that can concatenate several commands how StringBuilder does where for example we can have this :
B4X:
Dim sb1 As StringBuilder
sb1.Initialize
sb1.Append("Hello ").Append("from ").Append(B4A)
B4X:
Dim Arduino as ArduinoClass
Arduino.Initialize()
Arduino.pinMode(13, Arduino.OUTPUT).digitalWrite(13, HIGH)
Thank you very much to anyone who will get out of these doubts from my mind.