回复 6楼 Artless
我用了全局变量,可是form2设置的参数对form1不起任何作用。我的form2的代码是
Private Sub Form_Load()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
Else
End If
Combo1.AddItem "COM1"
Combo1.AddItem "COM2"
Combo1.AddItem "COM3"
Combo1.AddItem "COM4"
Combo1.AddItem "COM5"
Combo1.AddItem "COM6"
Combo1.AddItem "COM7"
Combo1.AddItem "COM8"
Combo1.ListIndex = 2
Combo2.AddItem "9600"
Combo2.AddItem "4800"
Combo2.AddItem "2400"
Combo2.AddItem "1200"
Combo2.ListIndex = 2
Combo4.AddItem "4"
Combo4.AddItem "5"
Combo4.AddItem "6"
Combo4.AddItem "7"
Combo4.AddItem "8"
Combo4.ListIndex = 4
Combo5.AddItem "1"
Combo5.AddItem "2"
Combo5.ListIndex = 0
= Combo1.ListIndex + 1 '使用COM4
MSComm1.Settings = "9600,n,8,1" '设置通信口参数
MSComm1.InBufferSize = 1024 '设置接收缓冲区为40 字节
MSComm1.OutBufferSize = 2 '设置发送缓冲区为2 字节
MSComm1.InputMode = comInputModeBinary '设置接收数据模式为二进制形式
MSComm1.InputLen = 1 '设置Input 一次从接收缓冲读取字节数为1
MSComm1.SThreshold = 1 '设置Output 一次从发送缓冲读取字节数为1
MSComm1.InBufferCount = 0 '清除接收缓冲区
MSComm1.OutBufferCount = 0 '清除发送缓冲区
w = 0 '数据个数计数器清零
MSComm1.RThreshold = 1 '设置接收一个字节产生OnComm 事件
End Sub
Private Sub Combo1_Click()
If MSComm1.PortOpen = True Then
'如果串口打开先关闭后再进行其他操作
MSComm1.PortOpen = False
End If
= Combo1.ListIndex + 1 '读取com口号
End Sub