A Antonio Teixeira Member Oct 4, 2021 #1 Hi everyone, I am trying to do something in B4R with the code I post here but for some reason that I cant understand I have an error in the code. Any help please? Thank you #Region Project Attributes #AutoFlushLogs: True #CheckArrayBounds: True #StackBufferSize: 300 #End Region Sub Process_Globals Public astream As AsyncStreams Public ReceivedCommand() As Byte Public Serial1 As Serial Public bc As ByteConverter End Sub Private Sub AppStart Serial1.Initialize(115200) astream.Initialize(Serial1.Stream, "Astream_NewData", "Astream_Error") ' End Sub Sub Astream_NewData (Buffer() As Byte) ReceivedCommand = bc.SubString2(Buffer, 0,2) ' <<<<<< This line dont compile with ' Main - 25: Cannot modify Const variable. (global non-primitive variables are always constants.) Log("ReceivedCommand: ", ReceivedCommand) End Sub Sub AStream_Error Log("error") End Sub
Hi everyone, I am trying to do something in B4R with the code I post here but for some reason that I cant understand I have an error in the code. Any help please? Thank you #Region Project Attributes #AutoFlushLogs: True #CheckArrayBounds: True #StackBufferSize: 300 #End Region Sub Process_Globals Public astream As AsyncStreams Public ReceivedCommand() As Byte Public Serial1 As Serial Public bc As ByteConverter End Sub Private Sub AppStart Serial1.Initialize(115200) astream.Initialize(Serial1.Stream, "Astream_NewData", "Astream_Error") ' End Sub Sub Astream_NewData (Buffer() As Byte) ReceivedCommand = bc.SubString2(Buffer, 0,2) ' <<<<<< This line dont compile with ' Main - 25: Cannot modify Const variable. (global non-primitive variables are always constants.) Log("ReceivedCommand: ", ReceivedCommand) End Sub Sub AStream_Error Log("error") End Sub
Erel B4X founder Staff member Licensed User Longtime User Oct 5, 2021 #2 Please use [code]code here...[/code] tags when posting code. Upvote 0
C candide Active Member Licensed User Longtime User Oct 5, 2021 #3 Public ReceivedCommand() As Byte => it is global variable without size and it is const i didn't test but you can change in this way: Code: Sub Astream_NewData (Buffer() As Byte) dim ReceivedCommand() = bc.SubString2(Buffer, 0,2) Log("ReceivedCommand: ", ReceivedCommand) End Sub Upvote 0
Public ReceivedCommand() As Byte => it is global variable without size and it is const i didn't test but you can change in this way: Code: Sub Astream_NewData (Buffer() As Byte) dim ReceivedCommand() = bc.SubString2(Buffer, 0,2) Log("ReceivedCommand: ", ReceivedCommand) End Sub
A Antonio Teixeira Member Oct 5, 2021 #4 Thank you Candide. The problem is that I need that variable ReceivedCommand along all program, I am going to try to define with size to check if works. Upvote 0
Thank you Candide. The problem is that I need that variable ReceivedCommand along all program, I am going to try to define with size to check if works.