Sub Class_Globals
'List of char/int16 that make up the command
Private data As List
End Sub
Public Sub Initialize(command As Char)
data.Initialize 'Can't use Initialize2 here because then we won't be able to add new items
data.Add(command)
End Sub
Public Sub AddNumberArgument(arg As Char)
data.Add(arg)
End Sub
Public Sub AddStringArgument(arg As String)
For i = 0 To arg.Length - 1
data.Add(Asc(arg.CharAt(i)))
Next
End Sub
Public Sub ToByteArray As Byte()
data.InsertAt(0, data.Size) 'Add number of chars of command
Dim byteArray(data.Size * 2) As Byte '1 char = 2 bytes
For i = 0 To data.Size - 1
'Split char into its two bytes
byteArray(i * 2) = Bit.ShiftRight(Bit.And(data.Get(i), 0xFF00), 8)
byteArray(i * 2 + 1) = Bit.And(data.Get(i), 0xFF)
Next
Return byteArray
End Sub