First time using long variables, so I need little clarification...
When I used word variables, I used this code to receive it:
In VB6 code for extracting bytes from word and to send:Code:CNT1 VAR WORD PC_in: SERIN2 Rx,84,3000,PC_in,[WAIT("DATA:"), CNT.byte1,CNT1.byte0] 'And to display it: SEROUT2 Tx,84,["CNT1:",DEC5 CNT1,10,13]
Now I tried same with word variables:Code:Private Sub Command1_Click() Dim Str As String, B1 As Byte, B2 As Byte Dim CNT As Long, C1 As long CNT = CLng(TxtCNT.Text) C1 = 256 B2 = Br \ C1 B1 = Br - C1 * B2 Str = "DATA:" & Chr(B2) & Chr(B1) MsComm1.Output=Str End Sub
PBP:
VB:Code:CNT VAR LONG PC_in: SERIN2 Rx,84,3000,PC_in,[WAIT("DATA:"), CNT.BYTE3, CNT1.BYTE2, CNT1.BYTE1, CNT1.BYTE0] SEROUT2 Tx,84,["CNT1:",DEC9 CNT1,10]
But doesn't work.Code:Dim Str As String, B1 As Byte, B2 As Byte, B3 As Byte, B4 As Byte, Dim CNT As Long, C1 As Long, C2 As Long, C3 As Long, C4 As Long CNT = CLng(TxtCNT.Text) C1 = 16777216 C2 = 65536 C3 = 256 B4 = CNT \ C1 CNT = CNT - B4 * C1 B3 = CNT \ C2 CNT = CNT - B3 * C2 B2 = CNT \ C3 B1 = CNT - C3 * B2 Str = "DATA:" & B4 & B3 & B2 & B1 MsComm1.Output=Str End Sub
VB extracted and sent bytes correctly.
But for example when I sent number 400401402, I receive 842215986.
Does anyone know why this happens and how to correct that?
EDIT:
Now I see mistake
Maybe it's time to rest a little
VB obviously not sending correctly, It should be
Excuse me for harassment.Code:Str = "DATA:" & Chr(B4) & Chr(B3) & Chr(B2) & Chr(B1)






Bookmarks