Private Sub Command1_Click()
'“转换”按钮
Dim d As Long
d = Val(Text1.Text)
Text2.Text = fntran(d, 2)
'转换为二进制数
Text3.Text = fntran(d, 8)
'转换为八进制数
Text4.Text = fntran(d, 16)
'转换为十六进制数
End Sub
Function fntran(ByVal d As Long, r As Integer) As String
Dim t As String, n As Integer
t = ""
Do While d > 0
'直到商为0
n = d Mod r
'取余数
d = d \ r
'求商
If n > 9 Then
'超过9转换成对应的A~F十六进制数表示形式
t = Chr(n + 55) & t
'换码为字母,反序加入
Else
t = n & t
'反序加入
End If
Loop
fntran = t
End Function