用VB语言编写程式实现2-16进制内任意进制之间的转换。希望有大神帮忙。

2025-03-31 05:26:43
推荐回答(1个)
回答1:

Private Sub Command1_Click()

  n1 = CInt(Text1)

  For i = 1 To Len(Text2)

    c = Mid(Text2, i, 1)

    If c >= "0" And c <= "9" Then

      If c < Chr(48 + n1) Then

        s = s * n1 + Asc(c) - 48

      Else

        MsgBox ("输入的数据有误!")

        Text2 = ""

        Exit Sub

      End If

    Else

      If c >= "a" And c <= "f" Then c = Chr(Asc(c) - 32)

      If c < "A" Or c > "F" Then

        MsgBox ("输入的数据有误!")

        Text2 = ""

        Exit Sub

      End If

    End If

  Next i


  n2 = CInt(Text3)

  s1 = ""

  While s > 0

    c = s Mod n2

    If c <= 9 Then

      s1 = c & s1

    Else

      s1 = Chr(55 + c) & s1

    End If

    s = s \ n2

  Wend

  Text4 = s1

End Sub


Private Sub Form_Load()

  Text1 = ""

  Text2 = ""

  Text3 = ""

  Text4 = ""  

End Sub