Private Sub command1_Click(Index As Integer)
Dim outstring As String, i As Integer
MSComm1.OutBufferCount = 0
If MSComm1.PortOpen = False Then
MsgBox "串口未打开", 52, "提示"
Else
outstring = Trim(Text2.Text)
If Combo1.ListIndex = 1 Then
outstring = Change_S(outstring, Combo1.ListIndex)
ElseIf Combo1.ListIndex = -1 Or Combo1.ListIndex = 0 Then
outstring = Change_S(outstring, 0)
End If
For i = 1 To Len(outstring)
MSComm1.Output = Mid(outstring, i, 1)
Next i
If outstring = "" Then
MsgBox "无发送数据!", 52, "提示"
Else
' Text2.Text = ""
End If
End If
End SubPrivate Sub Command2_Click()
Dim Instring As String, temp As String, i As Integer, xs As Integer
Dim xh As Integer
xh = Combo1.ListIndex
If Combo1.ListIndex = -1 Then
xh = 0
End If
If MSComm1.PortOpen = False Then
MsgBox "串口未打开", 52, "提示"
Else
On Error Resume Next
'轮询数据
jmp1: Do
DoEvents
Loop Until MSComm1.InBufferCount >= 0
Instring = MSComm1.Input
If xianshi = 0 Then
For i = 1 To Len(Instring)
If i Mod 2 = 0 Then
Text1.Text = Text1.Text & Change_R(Instring, xh) & " "
Else
Text1.Text = Text1.Text & Change_R(Instring, xh)
End If
Next i
Else
For i = 1 To Len(Instring)
If i Mod 8 = 0 Then
Text1.Text = Text1.Text & Change_R(Instring, xh) & " "
Else
Text1.Text = Text1.Text & Change_R(Instring, xh)
End If
Next i
End If
GoTo jmp1
End If
End SubPrivate Sub Command3_Click()
Text1.Text = ""
End SubPrivate Sub Command4_Click()
Form2.Enabled = True
Form2.Visible = True
Form2.Show
End SubPrivate Sub Command5_Click()
End
End SubPrivate Sub Command6_Click()
Dim t As Integer
Dim a As Integer
a = Form2.comport
Select Case a
Case 1
MSComm1.CommPort = 1
Case 2
MSComm1.CommPort = 2
Case 3
MSComm1.CommPort = 3
Case 4
MSComm1.CommPort = 4
Case 5
MSComm1.CommPort = 5
Case 6
MSComm1.CommPort = 6
End Select
MSComm1.Settings = Form2.comsetting
t = StrComp(Command6.Caption, "串口打开")
If Not t Then
Command6.Caption = "串口关闭"
MSComm1.PortOpen = False
t = 0
Else
Command6.Caption = "串口打开"
MSComm1.PortOpen = True
If comEvReceive Then
MSComm1.InBufferCount = 0
Instring = Instring & MSComm1.Input
End If
End If
Me.Show
End Sub
Private Function Change_S(strs As String, x As Integer) As String
Show
Dim i As Integer, t As Integer
Dim s As String, m As String, temp As String, lishi As String
If x = 0 Then
For i = 1 To Len(strs) Step 3
s = Mid(strs, i, 2)
m = m & s
Next i
ElseIf x = 1 Then
For i = 1 To Len(strs) Step 9
s = Mid(strs, i, 8)
m = m & s
Next i
End If
For i = 1 To Len(m)
lishi = Mid(m, i, 1)
t = Asc(Mid(m, i, 1))
If t >= 48 And t <= 57 Then
s = Chr(t - 48)
ElseIf t >= 65 And t <= 70 Then
s = Chr(t - 55)
ElseIf t >= 97 And t <= 102 Then
s = Chr(t - 87)
End If
temp = temp & s
Next i
Change_S = temp
End Function
Private Function Change_R(strs As String, x As Integer) As String
Show
Dim t As Integer
Dim s As String, m As String, temp As String t = Asc(strs)
If t >= 48 And t <= 57 Then
Change_R = Chr(t + 48)
ElseIf t >= 65 And t <= 70 Then
Change_R = Chr(t + 56)
ElseIf t >= 97 And t <= 102 Then
Change_R = Chr(t + 88)
End If
Print Change_R
'If x = 0 Then
'ElseIf x = 1 Then
' For i = 0 To Len(strs) Step 8
' s = Mid(strs, i, 8) & " "
' m = m & s
' Next i
'End If
'Change_R = m
End Function
Private Sub Command7_Click()
CommonDialog1.FileName = ""
CommonDialog1.Flags = vbOFNFileMustExist
CommonDialog1.Filter = "*.txt"
CommonDialog1.FilterIndex = 3
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.Action = 1
If CommonDialog1.FileName = "" Then
MsgBox "no file select ", 37, "checking"
Else
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Input #1, b$
a$ = UCase(b$)
Text2.Text = Text2.Text + a$ + Chr(13) + Chr(10)
Loop
End If
CloseEnd SubPrivate Sub Command8_Click()
CommonDialog1.CancelError = False
CommonDialog1.DefaultExt = "txt"
CommonDialog1.FileName = "lbw.txt"
CommonDialog1.Filter = "*.txt"
CommonDialog1.FilterIndex = 1
CommonDialog1.DialogTitle = "保存"
CommonDialog1.Flags = vbofnoverwriteprompt Or vbofnpathmustexist
CommonDialog1.Action = 2
Open CommonDialog1.FileName For Output As #1
Print #1, Text1.Text
CloseEnd Sub
帮我解决的话加我QQ909444414 小弟会用别的方式感激
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货