- Home
·
- Math/Dates
·
- Convert Hex values to their decimal equilivant. Great for color functions.
Convert Hex values to their decimal equilivant. Great for color functions.
Convert Hex values to their decimal equilivant. Great for color functions.
Rate Convert Hex values to their decimal equilivant. Great for color functions.
(2(2 Vote))
Static X, R As Integer
Static Stripped, Temp1, Temp2, Temp3 As Variant
On Error GoTo Exit_Me:
'* Start Comment Block ***********************************
'* Generated using VB 3.0 ToolBar
'* Author: Todd Wayman
'* Date: Mar, 22, 2001
'* Version: 1.00
'* Copyright © 2001 Todd Wayman; All rights reserved.
'* Function Title: Hex2Dec
' *************************************************************
'*
'* Disclaimer:
'*
'* This software is provided AS IS without warranty of any kind, either
'* express or implied. This includes without limitation the fitness for
'* a particular purpose or application and any warranties of merchantability.
'* The author shall not be liable for any damage, whether direct, indirect,
'* special, or consequential, arising from a failure of this software or
'* accompanying files to operate in a manner desired by the user. The author
'* shall not be liable for any damage to data or property which may be
'* caused directly or indirectly by the use of this program.
'* By using and/or installing this software YOU assume all responsibility.
'*
'* End Disclaimer
'*
'* Comments:
'* Function converts any hex value into it's decimal equilvant.
'* Valid hex values: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
'*
'* Usage:
'*
'* Dim X as Long
'*
'* X = Hex2Dec(FFF)
'* or
'* X = Hex2Dec(&HFFF)
'*
'* Returns:
'*
'* X = 4095
'*
'* VB 3.0 or greater
'*
'* End Comment Block *************************************
Stripped = UCase(Trim(HexVal)) 'Filter all Spaces before and after string and convert to all upper case
' If &H preceed the value strip it
If InStr(1, Stripped, "&H") = 0 Then
Temp1 = Stripped
ElseIf Mid(Stripped, 1, 2) = "&H" Then
Temp1 = Mid(Stripped, 3)
Stripped = Temp1 'Set stripped to the filtered value
End If
Temp3 = 0
' Code segment added by VB 3.0 Tool Bar
For X = 1 To Len(Stripped)
Temp2 = Mid(Temp1, 1, 1)
Select Case Temp2
Case "A"
Temp2 = "10"
Case "B"
Temp2 = "11"
Case "C"
Temp2 = "12"
Case "D"
Temp2 = "13"
Case "E"
Temp2 = "14"
Case "F"
Temp2 = "15"
End Select
Temp1 = Mid(Temp1, 2)
R = (Len(Stripped) + 1) - X
Temp3 = Val(Temp3) + (Val(Temp2) * (16 ^ (R - 1)))
Next X
' End Code Segment
Hex2Dec = CLng(Temp3)
Exit Function
Exit_Me:
Exit Function
End Function
Convert Hex values to their decimal equilivant. Great for color functions. Comments
No comments yet — be the first to post one!
Post a Comment