修改如下:
Private Sub Command2_Click(Index As Integer)
If Command2(index).Caption = "打开串口" Then
MSComm1.PortOpen = True
Command2(index).Caption = "关闭串口"
Else
Command2(index).Caption = "打开串口"
MSComm1.PortOpen = False
End If
End Sub
Private Sub Command2_Click(Index As Integer) ''''' index是数组,这里没有啊。
==把括号中的内容去掉
你这按钮控件是数组,要对应 index。可以在属性列表找到index。如Command2(1).Caption = "打开串口"