大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
成都创新互联主营临沧网站建设的网络公司,主营网站建设方案,app软件开发公司,临沧h5重庆小程序开发搭建,临沧网站营销推广欢迎临沧等地区企业咨询
MsgBox(DEC_to_HEX(255))
End Sub
Public Function DEC_to_HEX(ByVal Dec As Long) As String
Dim a As String
DEC_to_HEX = ""
Do While Dec 0
a = CStr(Dec Mod 16)
Select Case a
Case "10" : a = "A"
Case "11" : a = "B"
Case "12" : a = "C"
Case "13" : a = "D"
Case "14" : a = "E"
Case "15" : a = "F"
End Select
DEC_to_HEX = a DEC_to_HEX
Dec = Dec \ 16
Loop
End Function
下面代码就是将文本框中以一个空格隔开的十六进制转为字节的代码,文本框中数字格式为:01 02 03
Dim TestArray() As String = Split(TextBox1.Text)
Dim hexBytes() As Byte
ReDim hexBytes(TestArray.Length - 1)
Dim i As Integer
For i = 0 To TestArray.Length - 1
hexBytes(i) = Val("h" TestArray(i))
Next
SerialPort.Write(hexBytes, 0, hexBytes.Length)
Option Explicit
Dim Jz As Integer, K As Boolean
Private Sub Command1_Click()
Pic.Cls
If K Then Jz = Val(Qtjz.Text)
If Pd(Text1.Text, Jz) Then Pic.Print "选择的进制与数不符": Exit Sub
If Jz = 0 Then Pic.Print "请先输入进制" Else Pic.Print Zh(Text1.Text, Jz)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub Option1_Click(Index As Integer)
K = False
Select Case Index
Case 0
Jz = 2
Case 1
Jz = 8
Case 2
Jz = 10
Case 3
Jz = 16
Case 4
K = True
Qtjz.Text = ""
Qtjz.SetFocus
End Select
If Index 4 Then Command1.SetFocus
End Sub
Private Sub Qtjz_Click()
Qtjz.Text = ""
End Sub
Private Sub Text1_Click()
Text1.Text = ""
End Sub
Private Function Zh(a As String, b As Integer) As Integer
Dim c As String, i, d As Integer
a = LCase(a)
For i = 1 To Len(a)
c = Mid(a, Len(a) + 1 - i, 1)
If Asc(c) 96 Then d = Asc(c) - 87 Else d = Val(c)
Zh = Zh + d * b ^ (i - 1)
Next i
End Function
Private Function Pd(a As String, b As Integer) As Boolean
Dim c As String, i, d As Integer
Pd = False
For i = 1 To Len(a)
c = Mid(a, Len(a) + 1 - i, 1)
If Asc(c) 96 Then d = Asc(c) - 87 Else d = Val(c)
If d b - 1 Then Pd = True: Exit Function
Next i
End Function
numHex =Integer.Parse(strHex, Globalization.NumberStyles.AllowHexSpecifier)
或
numHex = Integer. Parse("H" strHex)