Formatting Hexadecimal - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Formatting Hexadecimal

mp3guymp3guy Posts: 24Member
I need to format a load of hexadecimal numbers. They go from 0 to FFFFFF. If I try to use

[code]Format(Text1.Text, "000000")[/code]

saying text1.text contains 4104F, it returns 4104F. I need it to return 04104F. Is there any way to do it? And the hex length is varying, could be 2 characters, like 4A or 6 chars like 564A89.

Comments

  • infidelinfidel Posts: 2,900Member
    [b][red]This message was edited by infidel at 2004-11-29 14:58:59[/red][/b][hr]
    : I need to format a load of hexadecimal numbers. They go from 0 to FFFFFF. If I try to use
    :
    : [code]Format(Text1.Text, "000000")[/code]
    :
    : saying text1.text contains 4104F, it returns 4104F. I need it to return 04104F. Is there any way to do it? And the hex length is varying, could be 2 characters, like 4A or 6 chars like 564A89.

    Something like this?

    [code]
    Private Sub Form_Load()

    MsgBox FormatHex("4A")
    MsgBox FormatHex("4104F")

    End Sub

    Private Function FormatHex(ByVal strValue As String) As String

    FormatHex = IIf(Len(strValue) Mod 2 = 0, strValue, "0" & strValue)

    End Function
    [/code]

    Or this?

    [code]
    Private Sub Form_Load()

    MsgBox FormatHex("4A")
    MsgBox FormatHex("4104F")

    End Sub

    Private Function FormatHex(ByVal strValue As String) As String

    FormatHex = Right("000000" & strValue, 6)

    End Function
    [/code]

    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]



Sign In or Register to comment.