BlueIshDan
☠
- Local time
- Today, 18:50
- Joined
- May 15, 2014
- Messages
- 1,122
I've been looking into writing an access form used for hard drive analysis and came across hex values. This made me start dabbling with numbers again and came up with the following function.
If you're a person that enjoys playing with numbers, could I get you to think of any scenarios where I could solidify this function to handle errors and become as dynamic as possible!
I think the end result could be useful to add to this communities quick fix library.
What it does is take two strings, value and and the definition of how that numbers counts, and with these two values it will spit out the decimal value.
examples:
HEX - "FFF", "0123456789ABCDEF"
OCT - "777", "01234567"
BINARY - "11111110", "01"
Thanks,
Blue
If you're a person that enjoys playing with numbers, could I get you to think of any scenarios where I could solidify this function to handle errors and become as dynamic as possible!
I think the end result could be useful to add to this communities quick fix library.
What it does is take two strings, value and and the definition of how that numbers counts, and with these two values it will spit out the decimal value.
examples:
HEX - "FFF", "0123456789ABCDEF"
OCT - "777", "01234567"
BINARY - "11111110", "01"
Code:
Public Function ConvertStringToDecimal(ByVal str As String, _
ByVal def As String) As Variant
Dim inc As Integer: inc = Len(def)
Dim n As Variant: n = CDec(0)
Dim i As Integer
Dim val As Integer
For i = Len(str) To 1 Step -1
val = InStr(1, def, Mid(str, i, 1))
If val > 0 Then: n = n + CDec((val - 1) * (inc ^ (i - 1)))
Next
ConvertStringToDecimal = n
End Function
Thanks,
Blue
Last edited: