Private Sub Command1_Click ()
Dim strLen As Integer
Dim HSTR As String * 1
Dim LSTR As String * 1
Dim dataMe As Integer
Dim mytext1 As String
Dim nbyte () As Byte
StrLen=Len (Text1. Text)
Mytext1=Text1. Text
For n=1 To strLen
N=n - 1
If n Mod 3=0 Then
HSTR=Mid (mytext1, 1, 1)
ElseIf n Mod 3=1 Then
LSTR=Mid (mytext1, 2, 1)
DataMe=StrToHex (HSTR) * 16 + StrToHex (LSTR)
Mytext1=Right (mytext1, Len (mytext1) - 2)
Nbyte (I)=dataMe
I=I + 1
N=n + 1
End the If
The Next n
MSComm1. The Output=nbyte
End Sub
Display nbyte array subscript bounds is why,,, hope you guide
CodePudding user response:
Array nbyte (1) you () is a dynamic array, before use the Redim statement to "distribution data space" (or with a non-empty array to assign a value to it), and then you can use,Without this step, you will have direct access to the array elements, can appear "array subscript cross-border operation error,"
(2) your For statement, written as (is there is a n=n - 1 in the beginning, control of variable step size is 1), can turn it into an infinite loop!
Don't you have to run the test? Have not found this problem???????
(3) your For loop control variable is n, behind and use of nbyte (I)=...
The two variables is not stated in the process, is it module-level variables or global variable?
Variable (I) in the process, is not the assignment, and no other statements used it,
You confirm your code didn't write wrong? Can I value to visit nbyte elements ()???????
(4) don't know your function StrToHex (HSTR) is what kind of, can also be difficult to "guess" what are you going to do this code,
Whether have some other problem, at present unknown,
CodePudding user response:
Be honestDo programmers to care