Chào các bạn. Mình đang làm VB6.0 giao tiếp với VDK.Mình gặp rắc rối là khi XOR 2 toán hạng thì khôg biết bị lỗi gì mà nó cứ báo lỗi Runtine error13. Mà nó chỉ bị mỗi dòng đó mới tức chứ.Bạn nào biết nguyên do chỉ mình với. Cám ơn nhiều
Private Sub cmdcheck_Click()
Dim j As Byte
Dim REQA(6), anti(6), uid(4), ui, BCC, selectA(4) As Byte
' Request
REQA(0) = &HAA
REQA(1) = &H0
REQA(2) = &H2
REQA(3) = &H3
REQA(4) = &H26
REQA(5) = &H27
REQA(6) = &HBB
MSComm1.InBufferCount = 0
For j = 0 To 6
tam = Val(REQA(j))
MSComm1.Output = Chr$(tam)
Next j
Text1.Text = 2 ^ 2
Delay (1)
'anticol
anti(1) = &HAA
anti(2) = &H0
anti(3) = &H1
anti(4) = &H4
anti(5) = &H5
anti(6) = &HBB
MSComm1.InBufferCount = 0
For j = 1 To 6
tam = Val(anti(j))
MSComm1.Output = Chr$(tam)
Next j
Delay (1)
uid(1) = Mid(g, 6, 1)
uid(2) = Mid(g, 7, 1)
uid(3) = Mid(g, 8, 1)
uid(4) = Mid(g, 9, 1)
' select
selectA(1) = &HAA
selectA(2) = &H0
selectA(3) = &H5
selectA(4) = &H5
BCC = selectA(2)
For j = 3 To 4
BCC = BCC Xor selectA(j)
Next j
ui = uid(1)
For j = 2 To 4
ui = ui Xor uid(j) ' lỗi dòng này
Next j
BCC = BCC Xor ui
For j = 1 To 4
tam = Val(selectA(j))
MSComm1.Output = Chr$(tam)
Next j
For j = 1 To 4
tam = Val(uid(j))
MSComm1.Output = Chr$(tam)
Next j
MSComm1.Output = Chr$(Val(BCC))
MSComm1.Output = Chr$(Val(&HBB))
Delay (1)
For j = 1 To Len(g)
Text3.Text = Asc(Mid(g, j, 1))
Delay (1)
Next j
End Sub
Private Sub cmdcheck_Click()
Dim j As Byte
Dim REQA(6), anti(6), uid(4), ui, BCC, selectA(4) As Byte
' Request
REQA(0) = &HAA
REQA(1) = &H0
REQA(2) = &H2
REQA(3) = &H3
REQA(4) = &H26
REQA(5) = &H27
REQA(6) = &HBB
MSComm1.InBufferCount = 0
For j = 0 To 6
tam = Val(REQA(j))
MSComm1.Output = Chr$(tam)
Next j
Text1.Text = 2 ^ 2
Delay (1)
'anticol
anti(1) = &HAA
anti(2) = &H0
anti(3) = &H1
anti(4) = &H4
anti(5) = &H5
anti(6) = &HBB
MSComm1.InBufferCount = 0
For j = 1 To 6
tam = Val(anti(j))
MSComm1.Output = Chr$(tam)
Next j
Delay (1)
uid(1) = Mid(g, 6, 1)
uid(2) = Mid(g, 7, 1)
uid(3) = Mid(g, 8, 1)
uid(4) = Mid(g, 9, 1)
' select
selectA(1) = &HAA
selectA(2) = &H0
selectA(3) = &H5
selectA(4) = &H5
BCC = selectA(2)
For j = 3 To 4
BCC = BCC Xor selectA(j)
Next j
ui = uid(1)
For j = 2 To 4
ui = ui Xor uid(j) ' lỗi dòng này
Next j
BCC = BCC Xor ui
For j = 1 To 4
tam = Val(selectA(j))
MSComm1.Output = Chr$(tam)
Next j
For j = 1 To 4
tam = Val(uid(j))
MSComm1.Output = Chr$(tam)
Next j
MSComm1.Output = Chr$(Val(BCC))
MSComm1.Output = Chr$(Val(&HBB))
Delay (1)
For j = 1 To Len(g)
Text3.Text = Asc(Mid(g, j, 1))
Delay (1)
Next j
End Sub