dim s as string dim c as byte s= "&h" & text1.text 'FF c=cbyte(s) 现在c的值就是十六进制FF,十进制255,二进制11111111或者这样 dim s as string Dim c() As Byte Dim i As Long, n As Long Dim s As String s = Text1.Text 'ABCDEF s = Replace(s, " ", "") '去掉空格 n = Len(s) If n Mod 2 <> 0 Then MsgBox "长度错误" Else ReDim c(0 To (n / 2) - 1) As Byte For i = 1 To n Step 2 c(i \ 2) = CByte("&h" & Mid(s, i, 2)) Next End If 数组C()里面存放的就是text1对应的十六进制数据
Private Sub Command1_Click() Dim s As String s = "&H" & Text1.Text s = CLng(s) MsgBox s End Sub
Option Explicit Dim sj As BytePrivate Sub Command1_Click() Print sj End SubPrivate Sub Form_Load() Text1 = "" End SubPrivate Sub Text1_Change() Dim i As Integer Text1 = UCase(Text1) If Len(Text1) = 2 Then For i = 1 To Len(Text1) If Asc(Mid(Text1, i, 1)) < 48 Or Asc(Mid(Text1, i, 1)) > 57 And Asc(Mid(Text1, i, 1)) < 65 Or Asc(Mid(Text1, i, 1)) > 70 Then Text1.SetFocus Text1 = "" Exit For Else sj = Val("&H" & Text1) Command1.SetFocus End If Next End If End Sub
Option Explicit Dim sj() As BytePrivate Sub Send() ReDim sj(Len(Text1) / 2 - 1) Dim i As Integer For i = 1 To Len(Text1) Step 2 sj((i - 1) / 2) = Val("&H" & Mid(Text1, i, 2)) Next MSComm1.Output = sj End SubPrivate Sub Form_Load() MSComm1.Settings = "9600,N,8,1" MSComm1.PortOpen = True Text1 = "" End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Dim i As Integer Text1 = UCase(Text1) For i = 1 To Len(Text1) If Asc(Mid(Text1, i, 1)) < 48 Or Asc(Mid(Text1, i, 1)) > 57 And Asc(Mid(Text1, i, 1)) < 65 Or Asc(Mid(Text1, i, 1)) > 70 Then Text1.SetFocus Text1 = "" Exit Sub End If Next If Len(Text1) Mod 2 = 0 Then Send End If End If End Sub
dim c as byte
s= "&h" & text1.text 'FF
c=cbyte(s)
现在c的值就是十六进制FF,十进制255,二进制11111111或者这样
dim s as string
Dim c() As Byte
Dim i As Long, n As Long
Dim s As String
s = Text1.Text 'ABCDEF
s = Replace(s, " ", "") '去掉空格
n = Len(s)
If n Mod 2 <> 0 Then
MsgBox "长度错误"
Else
ReDim c(0 To (n / 2) - 1) As Byte
For i = 1 To n Step 2
c(i \ 2) = CByte("&h" & Mid(s, i, 2))
Next
End If
数组C()里面存放的就是text1对应的十六进制数据
Dim s As String
s = "&H" & Text1.Text
s = CLng(s)
MsgBox s
End Sub
Dim sj As BytePrivate Sub Command1_Click()
Print sj
End SubPrivate Sub Form_Load()
Text1 = ""
End SubPrivate Sub Text1_Change()
Dim i As Integer
Text1 = UCase(Text1)
If Len(Text1) = 2 Then
For i = 1 To Len(Text1)
If Asc(Mid(Text1, i, 1)) < 48 Or Asc(Mid(Text1, i, 1)) > 57 And Asc(Mid(Text1, i, 1)) < 65 Or Asc(Mid(Text1, i, 1)) > 70 Then
Text1.SetFocus
Text1 = ""
Exit For
Else
sj = Val("&H" & Text1)
Command1.SetFocus
End If
Next
End If
End Sub
Dim sj() As BytePrivate Sub Send()
ReDim sj(Len(Text1) / 2 - 1)
Dim i As Integer
For i = 1 To Len(Text1) Step 2
sj((i - 1) / 2) = Val("&H" & Mid(Text1, i, 2))
Next
MSComm1.Output = sj
End SubPrivate Sub Form_Load()
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
Text1 = ""
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Dim i As Integer
Text1 = UCase(Text1)
For i = 1 To Len(Text1)
If Asc(Mid(Text1, i, 1)) < 48 Or Asc(Mid(Text1, i, 1)) > 57 And Asc(Mid(Text1, i, 1)) < 65 Or Asc(Mid(Text1, i, 1)) > 70 Then
Text1.SetFocus
Text1 = ""
Exit Sub
End If
Next
If Len(Text1) Mod 2 = 0 Then
Send
End If
End If
End Sub