|
-
Jul 18th, 2005, 08:28 PM
#1
Thread Starter
Fanatic Member
Converting a Long to a Hex string.[resolved]
I'd like to convert a long to a hex string, basically just a six digit color code. Someone have the code on this?
Last edited by Nove; Jul 20th, 2005 at 09:28 AM.
-
Jul 18th, 2005, 08:40 PM
#2
Re: Converting a Long to a Hex string.
Try this:
VB Code:
Function LongToHex(ByVal lValue As Long) As String
LongToHex = "&H" & Hex(lValue)
End Function
-
Jul 18th, 2005, 08:44 PM
#3
Thread Starter
Fanatic Member
Re: Converting a Long to a Hex string.
That works fairly well, but if the number isn't big enough it's not going to fill six digits. For instance, pure white on there is going to just be "&H0". It's still Hex, but later I'm going to want to split the Hex into it's RGB components, which will require more code if it's not at the right length. Is there a better hex conversion, or even a good method of converting a long number into RGB?
-
Jul 18th, 2005, 08:55 PM
#4
Re: Converting a Long to a Hex string.
In that case you can modify function as follows:
VB Code:
Function LongToHex(ByVal lValue As Long) As String
Dim strHex As String
strHex = Hex(lValue)
If Len(strHex) < 6 Then
strHex = String(6 - Len(strHex), "0") & strHex
End If
strHex = "&H" & strHex
LongToHex = strHex
End Function
-
Jul 20th, 2005, 09:28 AM
#5
Thread Starter
Fanatic Member
Re: Converting a Long to a Hex string.[resolved]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|