請問一下這個要如何寫
我的input是textbox
我的output是msgbox
謝謝
2005-07-04 17:32:25 · 4 個解答 · 發問者 Anonymous in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click()
sum = 0
n = Len(Text1.Text)
For i = 0 To n - 1
Select Case UCase(Mid(Text1.Text, i + 1, 1))
Case "1"
sum = sum + 16 ^ (n - 1 - i) * 1
Case "2"
sum = sum + 16 ^ (n - 1 - i) * 2
Case "3"
sum = sum + 16 ^ (n - 1 - i) * 3
Case "4"
sum = sum + 16 ^ (n - 1 - i) * 4
Case "5"
sum = sum + 16 ^ (n - 1 - i) * 5
Case "6"
sum = sum + 16 ^ (n - 1 - i) * 6
Case "7"
sum = sum + 16 ^ (n - 1 - i) * 7
Case "8"
sum = sum + 16 ^ (n - 1 - i) * 8
Case "9"
sum = sum + 16 ^ (n - 1 - i) * 9
Case "A"
sum = sum + 16 ^ (n - 1 - i) * 10
Case "B"
sum = sum + 16 ^ (n - 1 - i) * 11
Case "C"
sum = sum + 16 ^ (n - 1 - i) * 12
Case "D"
sum = sum + 16 ^ (n - 1 - i) * 13
Case "E"
sum = sum + 16 ^ (n - 1 - i) * 14
Case "F"
sum = sum + 16 ^ (n - 1 - i) * 15
Case Else
MsgBox "輸入錯誤,請重新輸入,程式將結束~~"
End
End Select
Next i
MsgBox "十六進位" & Text1.Text & "等於十進位" & sum
End Sub
2005-07-05 12:16:45 補充:
val函數可以辨認進位符號 &O (八進位) 與 &H (十六進位)
用法:
val("&HFF")=255
val("&O77")=63
2005-07-04 18:50:32 · answer #1 · answered by 上官 5 · 0⤊ 0⤋
a=textbox.text
msgbox val("&H" & a )
2005-07-06 15:43:48 · answer #2 · answered by Anonymous · 0⤊ 0⤋
MsgBox Val("&H" & Text1.Text)
2005-07-05 06:21:07 · answer #3 · answered by Brian 5 · 0⤊ 0⤋
HexValue = Text1.Text
DecValue = 0
IsIllegal = False
I = 1
Do While (I <= Len(HexValue)) And (Not IsIllegal)
C = Asc(UCase(Mid(HexValue, I, 1)))
DecValue = DecValue * 16
Select Case C
Case 48 To 57 '0 ~ 9 的ASCII值
DecValue = DecValue + (C - 48)
Case 65 To 70 'A~F的ASCII值
DecValue = DecValue + (C - 65 + 10)
Case Else
MsgBox "不合理的十六進位值!無法轉換為十進位值!"
IsIllegal = True
End Select
I = I + 1
Loop
MsgBox CStr(DecValue)
2005-07-04 18:55:08 · answer #4 · answered by Anonymous · 0⤊ 0⤋