canalrun Well-Known Member Licensed User Longtime User Feb 8, 2019 #1 I can't find the answer to this. I am using B4R 2.51 and a WeMos D1 R2 WiFi. I would like to create a global public array variable, set its value in AppStart, then use it in a third subroutine. Code: Copy Sub Process_Globals ... Public pktOff(), pktOn() As Byte ... End Sub Code: Copy Sub AppStart ... pktOff = bc.HexToBytes("2A00003418DD000000000000000000000000000000000100000000000000000075000000000064000000") pktOn = bc.HexToBytes("2A00003418DD000000000000000000000000000000000100000000000000000075000000FFFF64000000") ... End Sub Code: Copy Sub SendBulb(bon as boolean) ... If (bon) Then ' bon = true, bulb is on wudp.Write(pktOn) Else wudp.Write(pktOff) End If ... End Sub But, It gives me the error: Cannot modify Const variable. (global non-primitive variables are always constants). Is there a way to create global arrays? Is there a trick other than making pkton/off entirely local to Sub SendBulb? Thanks, Barry.
I can't find the answer to this. I am using B4R 2.51 and a WeMos D1 R2 WiFi. I would like to create a global public array variable, set its value in AppStart, then use it in a third subroutine. Code: Copy Sub Process_Globals ... Public pktOff(), pktOn() As Byte ... End Sub Code: Copy Sub AppStart ... pktOff = bc.HexToBytes("2A00003418DD000000000000000000000000000000000100000000000000000075000000000064000000") pktOn = bc.HexToBytes("2A00003418DD000000000000000000000000000000000100000000000000000075000000FFFF64000000") ... End Sub Code: Copy Sub SendBulb(bon as boolean) ... If (bon) Then ' bon = true, bulb is on wudp.Write(pktOn) Else wudp.Write(pktOff) End If ... End Sub But, It gives me the error: Cannot modify Const variable. (global non-primitive variables are always constants). Is there a way to create global arrays? Is there a trick other than making pkton/off entirely local to Sub SendBulb? Thanks, Barry.
Erel B4X founder Staff member Licensed User Longtime User Feb 8, 2019 #2 Your code is quite inefficient. Write it like this: Code: Copy Sub Process_Globals Dim pktOff() As Byte = Array As Byte(0x2A, 00,00, 0x34, 0x18D, 0xD0,00, ...) End Sub canalrun said: Is there a way to create global arrays? Click to expand... Don't use in this case, but the solution is: https://www.b4x.com/android/forum/threads/module-globalstore-global-objects-storage.73863/#content Upvote 0
Your code is quite inefficient. Write it like this: Code: Copy Sub Process_Globals Dim pktOff() As Byte = Array As Byte(0x2A, 00,00, 0x34, 0x18D, 0xD0,00, ...) End Sub canalrun said: Is there a way to create global arrays? Click to expand... Don't use in this case, but the solution is: https://www.b4x.com/android/forum/threads/module-globalstore-global-objects-storage.73863/#content