已经按你的要求修改过了。有两点需要说明:
1、可以把Form_Load去掉不会出现任何问题,但是前提是你需要保持输入内容的格式,如果格式不正确则不会得到正确的结果。
2、行数可以任意增加,每一行的数字个数可以任意增加,前提还是要[保持格式正确]。
好了,现在发给你:
Private Sub Command1_Click()
Dim T1 As String
Dim STR0 As String, Str1 As String
Dim N As Integer
Dim I As Integer, J As Integer, K As Integer
Dim A As Variant
STR0 = vbCrLf
T1 = Text1.Text
Do While Len(T1) > 0
N = InStr(T1, STR0)
If N = 0 Then
Str1 = T1
T1 = ""
Else
Str1 = Left(T1, N - 1)
T1 = Right(T1, Len(T1) - N - 1)
End If
A = Split(Str1, " ")
K = (UBound(A) + 1) \ 4
If (UBound(A) + 1) Mod 4 <> 0 Then K = K + 1
Text2.Text = Text2.Text & "a[0] = 0x00" & Format(UBound(A) + 1, "00") & "3902" & STR0
For I = 0 To K - 1
Text2.Text = Text2.Text & "a[" & I + 1 & "] = 0x"
For J = 3 To 0 Step -1
If I * 4 + J > UBound(A) Then
Text2.Text = Text2.Text & "00"
Else
Text2.Text = Text2.Text & A(I * 4 + J)
End If
Next
Text2.Text = Text2.Text & STR0
Next
Text2.Text = Text2.Text & "dsi_set_cmdq(&data_array, " & K + 1 & ", 1)" & STR0
Loop
End Sub
Private Sub Form_Load()
Text2.Text = ""
Text1.Text = "12 AB CD 5c 76 88 c2" & vbCrLf & "99 23 A3 44"
End Sub
已经运行过,你看还有什么问题没有,请留言。