求使用vb将十进制转化为十六进制的程序代码(是在没那么多积分了~在线等)

2024-11-17 07:50:30
推荐回答(4个)
回答(1):

给你一个我以前做的十进制转换为其他进制部分的代码:
Private Sub Option4_Click()
b = Val(InputBox("请输入转换后进制", " 输入", 16))
Label3.Caption = b & "进制"
Text2 = ""
l = Len(Text1)
If l > 9 Then
MsgBox "输入数据不能大于9位!"
Text1 = ""
Text1.SetFocus
GoTo 1000
End If
For i = 1 To l
s = Mid(Text1, i, 1)
If Asc(s) > 57 Or Asc(s) < 48 Then
MsgBox "输入的数不合法,请重新输入!", vbCritical,_ "错误"
Text1 = ""
Text1.SetFocus
Exit For
End If
Next i
X = Val(Text1.Text)
t = ""
Do
If b = 0 Then
MsgBox "进制数不能为零,请重新选择!", vbExclamation,_ "警告"
GoTo 1000
End If
'*************************************************这里才是算法
r = X Mod b
X = X \ b
If r >= 10 Then r = Chr(r + 55)
t = r & t
Loop Until X = 0
'*************************************************************
1000: Text2 = t
End Sub

回答(2):

text2=hex(text1)

回答(3):

Private Sub Command1_Click()

L = Len(Text1.Text)

Ta = ""
T2 = ""
If L <> 0 Then

For i = 1 To L

Ta = "%" & Hex(Asc(Mid(Text1.Text, i, 1)))

T2 = T2 & Ta

Next i

Text2.Text = T2

End If

End Sub

回答(4):

直接用HEX函数就可以了
Private Sub Command1_Click()
text2.text=hex(val(text1.text))
end suib