送分100分:MSComm1.Output = SHuZu(i)为什么不能用非要用 MSComm1.Output = SHuZu才可能 代码如下 dim SHuZu(5) as byte,i as integer for i =0 to 4 MSComm1.Output = SHuZu(i) '1、这种形式发送数据不成功 next i
Private Sub Command1_Click() Dim sj(2) As Byte Dim send As Variant sj(0) = 1 sj(1) = 2 sj(2) = 51 send = sj '将字节流转换到Variant变体变量send MSComm1.Output = sendEnd SubPrivate Sub Form_Load() MSComm1.PortOpen = TrueEnd Sub [解决办法]
以上的意思是说: 1、mscomm1.output可以发送文本或字节数据。 2、如果你想以文本方式发送数据,你可以用mscomm1.output直接发送字符串或字符串变量。 mscomm1.output="aaa" 或 dim temp as string temp = "aaa" mscomm1.output = temp 3、如果你想以字节方式发送数据,你必须以数组名来发送,你不能以数据成员来发送。 那怕你只想发送一字节数据,也得: dim temp(0) as byte temp(0) = 122 mscomm1.output = temp
[解决办法] 实践是检验真理的标准,我在1楼故意定义了2个变量,1个是 Dim sj(2) As Byte,字节数组 另1个是 Dim send As Variant,变体变量 按理:
VB code
Private Sub Command1_Click() Dim sj(2) As Byte Dim send As Variant sj(0) = 1 sj(1) = 2 sj(2) = 51 MSComm1.Output = sjEnd Sub [解决办法] http://download.csdn.net/source/1262066