VB将十进制整数转换成16进制以内的任意进制数
'数值转换,能够将十进制整数转换成16进制以内的任意进制数
Private Function DecToN(ByVal x%, ByVal n%) As String
Dim p() As String, y$, r%
p = Split("0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F", ",")
If n > 16 Then
DecToN = ""
Exit Function
End If
y = ""
Do
r = x Mod n
x = x \ n
y = p(r) & y
Loop Until x = 0
DecToN = y
End Function
Private Sub Command1_Click()
Dim x%, n%, y$
x = InputBox("请输入待转换的十进制整数!", "数值转换", 0)
n = InputBox("请输入需要的进制,注意不要大于16", "数值转换", 2)
y = DecToN(x, n)
If y <> "" Then
MsgBox "转换结果:" & DecToN(x, n)
Else
MsgBox "对不起!本程序不能转换超过16的进制!"
End If
End Sub