VB程序急急急!!!

来源:百度知道 编辑:UC知道 时间:2024/05/15 05:40:18
设置组单选框 第一组 A B C
第二组 A B C
第三组 A B C
现在我通过选择,比如说,第一组我选B,第二组我选A,第三组我选C。三组组合起来就是BAC,我想借助Mscomm控件用串口发送PBAC\n,也就是前后各加了一个字符。谁能帮我编一下呢。好用我可以再加分的。

界面设计:用三个frame控件作为第一组,第二组,第三组。每个frame框中添加三个optionButton控件,最好用控件数组,这样就是9个optionButton控件,加入名称都为opt。caption属性分别是A,B,C。添加一个mscomm控件,一个CommandButton控件。
代码如下:
Private Sub Command1_Click()
Dim i As Integer
Dim Str As String

'循环判断9个optionButton控件中哪个被选中了,并记下被选中的控件的名字
For i = 0 To 8
If Opt(i).Value = True Then
Str = Str & Opt(i).Caption
End If

Next i

'在获得的字符串前后分别加上字符
Str = "P" & Str & "\n"

'操作mscomm控件
With MSComm1
.CommPort = 1 '假定连接的是1号串口
.Settings = "9600,n,8,1" '设置波特率,假定是9600
.InBufferCount = 0 '清空缓冲区
.OutBufferCount = 0
.PortOpen = True '打开串口
.Output = Str '发送字符串
End With
End Sub

到天空软件园有啊

没玩过串口
不过就这个程序来说,你可以用重组一下!
str = "'"&a&b&c&"'"