Yay, about everything I hate about VB in one post. Anyway, one solution that works for me is Private Sub cmdConvert_Click() Dim Final As Long Dim i As Long Dim lengh As Long lengh = Len(txtHex.Text) Dim Hexs(lengh) As Integer For i = 1 To lengh If Not IsNumeric(Mid(txtHex.Text, i, 1)) Then Select Case Mid(txtHex.Text, i, 1) Case "A" : Hexs(i) = 10 Case "B" : Hexs(i) = 11 Case "C" : Hexs(i) = 12 Case "D" : Hexs(i) = 13 Case "E" : Hexs(i) = 14 Case "F" : Hexs(i) = 15 End Select Else Hexs(i) = Int(Mid(txtHex.Text, i, 1)) End If Next i Final = 0 For i = 1 To lengh Final = Final + Hexs(i) * 16 ^ (lengh - i) Next i txtDec.Text = Final End Sub though you might need to change it to your local VB dialect (mine is VB.Net 2005)
A better solution might be
Private Sub cmdConvert_Click() txtDec.Text = CLng("&H" & txtHex.Text) End Sub
|