Can someone tell me how to convert an Hexidecimal number to a Decimal number please, as i want to convert a hexadecimal colour of say a form to that of a decimal one...any1 know how?
Printable View
Can someone tell me how to convert an Hexidecimal number to a Decimal number please, as i want to convert a hexadecimal colour of say a form to that of a decimal one...any1 know how?
Have a look at this
http://forums.vb-world.net/showthrea...threadid=17995
Ok, that needed some maintenance, now you can use up to base 201
Code:' - - - - - - - K E D A M A N S C O D E- - - - - - -30.5.00 ( updated 9.6.00 )
' Base mod decimal converters
'IE bin 2 dec
' Base2dec("1234",2)
' oct 2 bin
' dec2base(Base2dec("1234",8),2)
'trin 2 hex
' dec2base(Base2dec("1234",3),16)
Function Base2Dec(val$, base%): Dim n%, a() As Byte
a = StrConv(UCase(val), vbFromUnicode)
For n = 1 To Len(val)
Base2Dec = CDec(Base2Dec + (a(n - 1) - 48 + 7 * (a(n - 1) > 64)) * base ^ (Len(val) - n))
Next n
End Function
Function Dec2Base$(val, base%): Dim n%, s
For n = 0 To 100
s = Int(val / base ^ n)
If s = 0 Then Exit For
s = s - Int(s / base) * base 's mod base
Dec2Base = Chr(s + 48 - 7 * (s > 9)) & Dec2Base
Next n
End Function
here:
Function HexToDec(TheHex As String) As Long
HexToDec = CLng("&H" & TheHex)
End Function
Hello Mag-Net,
Try this source:
Private Sub Command1_Click()
Dim Tabel As String
Dim Temp, N As Integer
Dim Answer As Long
Answer = 0
Tabel = "0123456789ABCDEF"
'if you want to create Octal to decimal: Tabel = "01234567"
Text1.Text = UCase(Text1.Text)
For N = 1 To Len(Text1.Text)
Temp = InStr(1, Tabel, Mid(Text1.Text, N, 1)) - 1
Answer = Answer + (16 ^ (Len(Text1.Text) - N)) * Temp
Next N
MsgBox Answer
End Sub
Good luck,
Michelle.
[Edited by michelle on 06-09-2000 at 03:55 AM]