📄 form1.frm
字号:
listIndex = Combo1.listIndex
Select Case listIndex
Case 0
bote = 9600
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
Case 1
bote = 4800
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
End Select
End Sub
Private Sub Combo2_Click() '这种分支语句与C++的太不同了
Dim cshuju As Integer
cshuju = Combo2.listIndex
Select Case cshuju
Case 0
shuju = 8
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
Case 1
shuju = 7
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
Case 2
shuju = 6
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
End Select
End Sub
Private Sub Combo3_Click()
Dim CtrlIndex As Integer
CtrlIndex = Combo3.listIndex
Select Case CtrlIndex
Case 0
jy = "n"
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
Case 1
jy = "o"
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
Case 2
jy = "e"
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
End Select
End Sub
Private Sub Combo4_Click()
Dim ctingzhi As Integer
ctingzhi = Combo4.listIndex
Select Case ctingzhi
Case 0
tingzhi = 1
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
Case 1
tingzhi = 2
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
End Select
End Sub
Private Sub Command1_Click()
If MSComm1.PortOpen = True Then
MSComm1.InputMode = comInputModeBinary
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
MSComm1.Output = Text1.Text
End If
If Text1.Text = "please" Then
bb = 1
End If
If Text1.Text = "begin" Then
Text2.Text = ""
Check1.Value = 1
biaoji5 = 0
End If
Text2.Text = ""
End Sub
Private Sub Command2_Click()
Text1.Text = ""
End Sub
Private Sub Command3_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub
Private Sub Command4_Click()
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
End Sub
Private Sub Command5_Click()
Dim fno As String
Dim i As Integer
'For i = 1 To 100
fno = FreeFile '这是固定格式FNO自己定义
Open "e:\保存文件.dat" For Output As #fno 'OPN要设置一个路径程序回自动生成文件
Print #fno, Text2.Text 'Text1.Text是要保存的文件内容地址
Close #fno
'Next i
End Sub
Private Sub Command6_Click()
Dim fno1 As String
Dim jilu As Byte
Dim binary As String
Dim i As Double
Dim bianliang As Double
Dim wenjian As String
Dim bl As Variant
Dim A() As Byte
Dim b As Double
Dim n As Double
Dim erjin() As Byte
Dim C(10) As Byte
Dim j As Integer
Dim p As Integer
Dim pd As Integer
Dim shiliu As String
Dim shiliu1 As String
Dim shiliu2 As String
Dim cishu As Integer
Dim cishu1 As Integer
Dim cishu2 As Integer
Dim z As Integer
Dim chuansong1 As String
Dim chuansong2 As String
Dim x As Integer
Dim kong As Integer
Dim shiliuzhuan As String
Dim zifuchuan As String
Dim c3() As Byte
Dim geshu5 As Integer
Dim n5 As Integer
'Text1.Text = ""
fno1 = FreeFile()
'bl = Dir1.Path + File1.FileName
Open "C:\Documents and Settings\David\桌面\regedt32.exe" For Binary As fno1 '为什么直接写路径就能打开文件,用了变量就打不开那 ?
changdu = LOF(fno1)
cishu1 = LOF(fno1) Mod 64
cishu2 = LOF(fno1) \ 64
' If cishu1 > 0 Then
' cishu = cishu2 + 1
' Else
' cishu = cishu2
ReDim A(changdu) As Byte
ReDim erjin(changdu) As Byte
'ReDim shiliuzhuan(64) As String
'p = 1
' For z = 1 To cishu
tex = Text2.Text
Select Case tex
Case "begin"
p = 1
Case "next"
p = jizhu
Case "error"
p = jizhu - 64
End Select
b = 0
pd = 0
n = 0
chuansong1 = ""
shiliu = ""
x = 0
For i = p To changdu '这里要实现64个字节读取
If pd < 64 Then
Get #fno1, i, A(x)
b = b + A(x)
If A(x) < 16 Then
shiliuzhuan = "0" + Hex(A(x))
x = x + 1
Else
shiliuzhuan = Hex(A(x))
End If
End If
pd = pd + 1
If pd > 64 Then
Exit For
End If
zifuchuan = zifuchuan & shiliuzhuan 'Text1.Text = Text1.Text & shiliuzhuan
Next i
jizhu = i
While (b > 0) '这里实现二进制转换
erjin(n) = b Mod 2
b = b \ 2
n = n + 1
Wend
For j = 0 To 7 '这里要实现低八位取出
C(j) = erjin(j)
Next j
If p < changdu Then
shiliu1 = Hex(C(0) * 1 + C(1) * 2 + C(2) * 4 + C(3) * 8)
shiliu2 = Hex(C(4) * 1 + C(5) * 2 + C(6) * 4 + C(7) * 8)
shiliu = shiliu2 + shiliu1
zifuchuan = zifuchuan & shiliu 'Text1.Text = Text1.Text & shiliu
Else
'Text1.Text = "ok"
' MSComm1.Output = Text1.Text
MsgBox "发送完成", vbOKOnly, "提示"
End If
' If Text2.Text = "error" Then
' Exit For
'Else
MSComm1.Output = zifuchuan
'Sleep (3000)
Text1.Text = ""
Text1.Text = zifuchuan
' End If
' Sleep (500)
'Next z
' Sleep (2000)
'End If
End Sub
Private Sub Command7_Click()
Text2.Text = ""
End Sub
Private Sub Command8_Click()
Dim fno1 As String
Dim changdu As Integer
fno1 = FreeFile()
Open "C:\Documents and Settings\David\桌面\regedt32.exe" For Binary As fno1 '为什么直接写路径就能打开文件,用了变量就打不开那 ?
changdu = LOF(fno1)
Text1.Text = changdu
End Sub
Private Sub Form_Load()
bote = 9600
jy = "n"
shuju = 8
tingzhi = 1
MSComm1.Settings = CStr(bote) + "," + jy + "," + CStr(shuju) + "," + CStr(tingzhi) '这种连这书写的方式要注意
MSComm1.PortOpen = True
MSComm1.RThreshold = 1 '准备开始接收
MSComm1.SThreshold = 1 '准备开始发送
End Sub
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim x As String
Dim m As Integer
Dim n As Integer
Dim geshu As Integer
Dim b As String
Dim zi As String
Dim z As String
Dim js As String
Dim quchu As Byte
Dim A() As String
Dim fno As String
Dim j As Integer
Dim cun() As String
Dim count As String
'Dim B As String
Dim xunze1 As Variant
Dim xunze2 As Variant
Dim xunze3() As Byte
Dim xunze4 As Variant
Dim xunze5 As Variant
Dim xunze6() As Byte
Dim xunze7() As Byte
Dim c1() As Byte
Dim p As Integer
Dim q As Integer
Dim t As Integer
Dim g As Integer
Dim Y As Integer
Dim s As Integer
Dim suum As Integer
Dim jystr As String
Dim jystr1 As String
Dim jystr2 As String
Dim zonghe() As Byte
Dim s8 As Integer
Dim aa() As Byte
MSComm1.InputLen = 1
MSComm1.InputMode = comInputModeBinary
Sleep (1000)
geshu = MSComm1.InBufferCount
Select Case MSComm1.CommEvent
Case comEvSend:
Case comEvReceive:
If Check1.Value = 0 Then
ReDim aa(geshu) As Byte
For s8 = 0 To geshu - 1
aa(s8) = MSComm1.Input(0)
Next s8
Text2.Text = ""
Text2.Text = Text2.Text + StrConv(aa, vbUnicode)
Select Case Text2.Text
Case "begin": tex = Text2.Text
Case "next": tex = Text2.Text
Case "error": tex = Text2.Text
End Select
If bb = 1 Then
x9 = Val(Text2.Text)
bb = 0
Text1.Text = ""
End If
If biaoji5 = 0 Then
ReDim wenjianbaocun(x9) As Byte ''''''''''''''''''''记录文件总长度
biaoji5 = 1
End If
End If
If Check1.Value = 1 Then
ReDim A(geshu - 1) As String '''''''''''''''''''记录130个字节存储,包括校验位
ReDim xunze3(geshu \ 2 - 2) As Byte
ReDim xunze6(geshu \ 2 - 2) As Byte
ReDim xunze7(geshu \ 2 - 2) As Byte
ReDim cun(geshu) As String
For n = 0 To geshu - 1
A(n) = Chr(MSComm1.Input(0))
Next n
Y = geshu \ 2
n = 0
For j = 0 To Y - 2
cun(2 * j) = A(2 * n)
xunze1 = cun(2 * j)
Select Case xunze1
Case "0"
xunze2 = 0
Case "1"
xunze2 = 1 * 16
Case "2"
xunze2 = 2 * 16
Case "3"
xunze2 = 3 * 16
Case "4"
xunze2 = 4 * 16
Case "5"
xunze2 = 5 * 16
Case "6"
xunze2 = 6 * 16
Case "7"
xunze2 = 7 * 16
Case "8"
xunze2 = 8 * 16
Case "9"
xunze2 = 9 * 16
Case "A"
xunze2 = 10 * 16
Case "B"
xunze2 = 11 * 16
Case "C"
xunze2 = 12 * 16
Case "D"
xunze2 = 13 * 16
Case "E"
xunze2 = 14 * 16
Case "F"
xunze2 = 15 * 16
End Select
xunze3(n) = xunze2
n = n + 1
jystr1 = A(geshu - 2)
Next j
q = 0
s = 0
For p = 0 To Y - 2
cun(2 * p + 1) = A(2 * s + 1)
xunze4 = cun(2 * p + 1)
Select Case xunze4
Case "0"
xunze5 = 0
Case "1"
xunze5 = 1
Case "2"
xunze5 = 2
Case "3"
xunze5 = 3
Case "4"
xunze5 = 4
Case "5"
xunze5 = 5
Case "6"
xunze5 = 6
Case "7"
xunze5 = 7
Case "8"
xunze5 = 8
Case "9"
xunze5 = 9
Case "A"
xunze5 = 10
Case "B"
xunze5 = 11
Case "C"
xunze5 = 12
Case "D"
xunze5 = 13
Case "E"
xunze5 = 14
Case "F"
xunze5 = 15
End Select
xunze6(q) = xunze5
q = q + 1
s = s + 1
jystr2 = A(geshu - 1)
Next p
Dim n1 As Integer
Dim shiliu3 As String
Dim shiliu4 As String
Dim erjin1(100) As Byte
Dim cerjin(10) As Byte
Dim j1 As Integer
Dim shiliu5 As String
ReDim zonghe((geshu - 2) \ 2 - 1)
suum = 0
g = 0
For t = 0 To Y - 2
xunze7(g) = xunze3(g) + xunze6(g)
zonghe(g) = xunze7(g) '后来加的
wenjianbaocun(e) = zonghe(g)
suum = suum + xunze7(g)
If g < 63 Then
g = g + 1 '后来加的
End If
e = e + 1
Next t
n1 = 0
While (suum > 0) '这里实现二进制转换
erjin1(n1) = suum Mod 2
suum = suum \ 2
n1 = n1 + 1
Wend
For j1 = 0 To 7 '这里要实现低八位取出
cerjin(j1) = erjin1(j1)
Next j1
'Text1.Text = Text1.Text & fno
shiliu3 = Hex(cerjin(0) * 1 + cerjin(1) * 2 + cerjin(2) * 4 + cerjin(3) * 8)
shiliu4 = Hex(cerjin(4) * 1 + cerjin(5) * 2 + cerjin(6) * 4 + cerjin(7) * 8)
shiliu5 = shiliu4 + shiliu3
jystr = jystr1 + jystr2
If shiliu5 = jystr Then
MSComm1.Output = "next"
Text2.Text = ""
Text3.Text = e
Sleep (500)
Text2.Text = "receive"
Else
MSComm1.Output = "error"
End If
If e = x9 Then
Check1.Value = 0
fno = FreeFile '这是固定格式FNO自己定义
Open "e:\保存文件.dat" For Binary As #fno
Put #fno, , wenjianbaocun 'Text1.Text是要保存的文件内容地址
MsgBox "文件保存", vbOKOnly, "提示"
Close #fno
End If
End If
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -