编写程序,利用sub过程把任意一个十进制整数n分别转化为二进制,八进制,十六进制数。

按照图形设计!谢谢!
2024-11-28 22:36:26
推荐回答(1个)
回答1:

Private Sub Text1_Change()
Dim n
If Len(Text1) > 0 And IsNumeric(Text1) Then
n = Val(Text1)
DEC_to_BIN n
DEC_to_OCT n
DEC_to_HEX n
Else
Text1 = ""
End If
End Sub
Sub DEC_to_BIN(ByVal Dec)
Label5.Caption = ""
Do While Dec > 0
Label5.Caption = Dec Mod 2 & Label5.Caption
Dec = Dec \ 2
Loop
End Sub
Sub DEC_to_OCT(ByVal Dec)
Label6.Caption = ""
Do While Dec > 0
Label6.Caption = Dec Mod 8 & Label6.Caption
Dec = Dec \ 8
Loop
End Sub
Sub DEC_to_HEX(ByVal Dec)
Dim a As String
Label7.Caption = ""
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
Label7.Caption = a & Label7.Caption
Dec = Dec \ 16
Loop
End Sub