我正在开发一个标记多选答案表的程序。例如:
我试图将来自OMR设备的数据输出转换为人类可读的格式,例如示例表的Q1 - 1,Q2 - 2等。
我的代码是:
Private Sub Form_Load()
Screen.MousePointer = 11
MSComm1.Handshaking = comRTS
MSComm1.RTSEnable = True
MSComm1.CommPort = 1
MSComm1.Settings = "19200,E,7,2"
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
Screen.MousePointer = 0
End Sub
Private Sub Command1_Click()
Dim Response As String
Dim TMCount As String
Dim CMode As String
Dim EMode() As String
Dim ReciveCnt As Integer
If MSComm1.DSRHolding = False Then
MsgBox "The device is not turned on" + Chr(&HD) + _
"or no communication cable is connected. !!", 16, "SR-430 Sample Program-1"
Screen.MousePointer = 0
Exit Sub
End If
If MSComm1.CTSHolding = False Then
MsgBox "The device is not in the receivable state. !!", 16, "SR-430 Sample Program-1"
Screen.MousePointer = 0
Exit Sub
End If
MSComm1.Output = Chr(&H18) + Chr(&HD)
Do
DoEvents
Loop Until MSComm1.InBufferCount = 1
Response = MSComm1.Input
If Response <> Chr(&H6) Then
MsgBox "Initialization fails !!"
Screen.MousePointer = 0
Exit Sub
End If
MSComm1.Output = Chr(&H13) + "12" + Chr(&HD)
MSComm1.Output = Chr(&H10) + "T" + Chr(&HD)
MSComm1.Output = Chr(&H2) + "2" + Chr(&HD)
MSComm1.Output = "?" + Chr(&HD)
ReciveCnt = 1
Do
DoEvents
Loop Until MSComm1.InBufferCount = ReciveCnt
Response = MSComm1.Input
If Response <> "0" Then
MsgBox "Error occurs!!" + Chr(&HD) + _
"Read status = " + Response
Screen.MousePointer = 0
Exit Sub
End If
MSComm1.Output = Chr(&H5) + "T" + Chr(&HD)
Do
DoEvents
Loop Until MSComm1.InBufferCount = 3
TMCount = MSComm1.Input
Text1.Text = "Timing mark count : " + TMCount + Chr(&HD) + Chr(&HA)
MSComm1.Output = Chr(&H10) + "C001" + TMCount + Chr(&HD)
Do
DoEvents
Loop Until MSComm1.InBufferCount = 3 * Val(TMCount)
CMode = MSComm1.Input
Text1.Text = Text1.Text + "C Mode : " + CMode + Chr(&HD) + Chr(&HA)
ReDim EMode(Val(TMCount)) As String
Dim DataLength As Integer
Text1.Text = Text1.Text + "E Mode : " + Chr(&HD) + Chr(&HA)
MSComm1.Output = Chr(&H10) + "E001" + TMCount + Chr(&HD)
ReciveCnt = 0
Response = " "
Do
DoEvents
Response = Response + MSComm1.Input
DataLength = InStr(Response, Chr(&HD))
If DataLength <> 0 Then
EMode(ReciveCnt) = Left(Response, DataLength)
Text1.Text = Text1.Text + Format(ReciveCnt + 1, "000") + "-Column:" + EMode(ReciveCnt) + Chr(&HA)
Response = Mid(Response, DataLength + 1)
ReciveCnt = ReciveCnt + 1
End If
Loop Until ReciveCnt = Val(TMCount)
Screen.MousePointer = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End
End Sub
给出了示例表的下面结果
Timing mark count : 036
C Mode : 00800500500500500500500500A005011300A8124201402800D1F000000000000000000F1F00000001F000F0006003F000000F000000
E Mode :
001-Column: 8
002-Column:9;
003-Column:9;
004-Column:9;
005-Column:9;
006-Column:9;
007-Column:9;
008-Column:9;
009-Column:8:
010-Column:9;
011-Column:7;
012-Column:23
013-Column:024;
014-Column:25:
015-Column:79
016-Column:68
017-Column:89;
018-Column:34567
019-Column:
020-Column:
021-Column:
022-Column:
023-Column:
024-Column:89:;
025-Column:34567
026-Column:
027-Column:
028-Column:34567
029-Column:89:;
030-Column:
031-Column:12
032-Column:234567
033-Column:
034-Column:89:;
035-Column:
036-Column:
如何修改代码以根据问题/答案提供所需的输出