先看如下代码
'...发送数据
Dim sData(1) As Byte
sData(0) = &H49
sData(1) = &HD
MSComm1.Output = sData '发送
怎么把sData发送的数据改成由用户自由输入,且数组长度不限,由用户决定
'...发送数据
Dim sData(1) As Byte
sData(0) = &H49
sData(1) = &HD
MSComm1.Output = sData '发送
怎么把sData发送的数据改成由用户自由输入,且数组长度不限,由用户决定
然后点击Command1按钮发送,在Command1里处理如下:
Private Sub Command1_Click()
Dim i As Integer
Dim sData() As Byte
Dim strData() As String
strData=Split(Text1.text," ")'//先提取数据
ReDim sData(Ubound(strData))'//确定数组大小
For i =0 to Ubound(strData)'//赋值转换
sData(i)=Val("&H" & strData(i))
Next
MSComm1.Output = sData '//发送
End Sub