B4R Question Array string variables

George Anifantakis

Member
Licensed User
Longtime User
I have a problem with wSensorLocID(8) string array.

B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private timer1 As Timer
 
    Private wSensorLocID(8) As String
    Private wSensorVAL(8) As Double
    Private wSensorTIMES(8) As Int

    Private pin16 As Pin
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    timer1.Initialize("timer1_Tick", 2000)
    timer1.Enabled = True
    InitArrays
End Sub

Private Sub InitArrays
    For wiic = 0 To wSensorLocID.Length -1
        wSensorLocID(wiic) = "123"
        wSensorTIMES(wiic) = 0
        wSensorVAL(wiic) = 0
    Next
    Log("Wicc -> ", wSensorLocID(0))  <------- here the variable is displayed correctly
End Sub

Sub Timer1_Tick
    Log("---1 ",    wSensorLocID(0))   <------- here the variable is not displayed correctly
    GetDevices
    Log("---3 ",    wSensorLocID(0))    <------- here the variable is not displayed correctly

End Sub

Private Sub GetDevices
    Log("---2 ", " Counter " ,   wSensorLocID(0))
End Sub

Variable wSensorLocID(0) is displayed corectly only inside InitArrays sub after initilization Log("Wicc -> ". The variable in timer gets strange characters or provides error Exception (28) if i use onewire lib.
 
Last edited:

thetahsk

Active Member
Licensed User
Longtime User

Modify your AppStart function
B4X:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    timer1.Initialize("timer1_Tick", 2000)
    InitArrays
    timer1.Enabled = True
    
End Sub
 
Upvote 0

George Anifantakis

Member
Licensed User
Longtime User
Hi,
I changed Appstart sub as shows above, but the problem still exist as shown below.



Modifying the line Log("---1 ", wSensorLocID(0) , wSensorTIMES(0) ) to display another one variable I'am getting an exeption(28) error.
I am using an ESP8266 module.

Thanks.
 
Upvote 0

George Anifantakis

Member
Licensed User
Longtime User
The code below

B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private timer1 As Timer
    'Private dt As DallasTemperature
 
    Private wSensorLocID(8) As String
    Private wSensorVAL(8) As Double
    Private wSensorTIMES(8) As Int

End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    timer1.Initialize("timer1_Tick", 2000)
    InitArrays
    timer1.Enabled = True
End Sub

Private Sub InitArrays
    For wiic = 0 To wSensorLocID.Length -1
        wSensorLocID(wiic) = "123"
        wSensorTIMES(wiic) = 0
        wSensorVAL(wiic) = 0
    Next
    Log("Wicc -> ", wSensorLocID(0) )
End Sub

Sub Timer1_Tick
    Log("---1 ",    wSensorLocID(0)  )
    GetDevices
    Log("---3 ",    wSensorLocID(0))

End Sub

Private Sub GetDevices
 
    Log("---2 ", " Counter " ,   wSensorLocID(0))
End Sub

And the result

 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…