Option Explicit Dim sendHex() As BytePrivate Sub Command1_Click() ReDim sendHex(0) sendHex(0) = &HAB MSComm1.Output = sendHex End SubPrivate Sub Form_Load() MSComm1.CommPort = 1 MSComm1.Settings = "9600,n.8,1" MSComm1.PortOpen = True End Sub或者: Option Explicit Dim sendHex() As BytePrivate Sub Command1_Click() ReDim sendHex(0) sendHex(0) = 171 MSComm1.Output = sendHex End SubPrivate Sub Form_Load() MSComm1.CommPort = 1 MSComm1.Settings = "9600,n.8,1" MSComm1.PortOpen = True End Sub
谢谢了。 要是我要发一串呢 AB 01 01 00 00 00 00 BA 不会要定义那么多个变量吧
Option Explicit Dim sendHex() As BytePrivate Sub Command1_Click() ReDim sendHex(1 to 8) sendHex(1) = &HAB sendHex(2) = &H1 sendHex(3) = &H0 sendHex(4) = &H0 sendHex(5) = &H0 sendHex(6) = &H0 sendHex(7) = &H0 sendHex(8) = &HBA MSComm1.Output = sendHex End SubPrivate Sub Form_Load() MSComm1.CommPort = 1 MSComm1.Settings = "9600,n.8,1" MSComm1.PortOpen = True End Sub
错了1字节,修正: Option Explicit Dim sendHex() As BytePrivate Sub Command1_Click() ReDim sendHex(1 to 8) sendHex(1) = &HAB sendHex(2) = &H1 sendHex(3) = &H1 sendHex(4) = &H0 sendHex(5) = &H0 sendHex(6) = &H0 sendHex(7) = &H0 sendHex(8) = &HBA MSComm1.Output = sendHex End SubPrivate Sub Form_Load() MSComm1.CommPort = 1 MSComm1.Settings = "9600,n.8,1" MSComm1.PortOpen = True End Sub
dim A(0) as Byte
A(0)=&HAB
MSComm1.Output=A
Dim sendHex() As BytePrivate Sub Command1_Click()
ReDim sendHex(0)
sendHex(0) = &HAB
MSComm1.Output = sendHex
End SubPrivate Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n.8,1"
MSComm1.PortOpen = True
End Sub或者:
Option Explicit
Dim sendHex() As BytePrivate Sub Command1_Click()
ReDim sendHex(0)
sendHex(0) = 171
MSComm1.Output = sendHex
End SubPrivate Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n.8,1"
MSComm1.PortOpen = True
End Sub
要是我要发一串呢
AB 01 01 00 00 00 00 BA
不会要定义那么多个变量吧
Dim sendHex() As BytePrivate Sub Command1_Click()
ReDim sendHex(1 to 8)
sendHex(1) = &HAB
sendHex(2) = &H1
sendHex(3) = &H0
sendHex(4) = &H0
sendHex(5) = &H0
sendHex(6) = &H0
sendHex(7) = &H0
sendHex(8) = &HBA
MSComm1.Output = sendHex
End SubPrivate Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n.8,1"
MSComm1.PortOpen = True
End Sub
Option Explicit
Dim sendHex() As BytePrivate Sub Command1_Click()
ReDim sendHex(1 to 8)
sendHex(1) = &HAB
sendHex(2) = &H1
sendHex(3) = &H1
sendHex(4) = &H0
sendHex(5) = &H0
sendHex(6) = &H0
sendHex(7) = &H0
sendHex(8) = &HBA
MSComm1.Output = sendHex
End SubPrivate Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n.8,1"
MSComm1.PortOpen = True
End Sub