VB编程:用户输入一个十进制数,通过菜单项选择该数转换为八进制和十六进制数

2024年11月16日 06:00
有1个网友回答
网友(1):

Private Sub OCT_Click()

  Dim n As Long

  n = CInt(Text1.Text)

  Label1.Caption = ""

  Do

    Label1.Caption = n Mod 8 & Label1.Caption

    n = n \ 8

  Loop While n > 0

  Label1.Caption = "八进制:" & Label1.Caption

End Sub


Private Sub HEX_Click()

  Dim n As Long, t As Long

  n = CInt(Text1.Text)

  Label2.Caption = ""

  Do

    t = n Mod 16

    If t < 10 Then

      Label2.Caption = t & Label2.Caption

    Else

      Label2.Caption = Chr(t + 55) & Label2.Caption

    End If

    n = n \ 16

  Loop While n > 0

  Label2.Caption = "十六进制:" & Label2.Caption


End Sub