Results 1 to 3 of 3

Thread: Hexadecimal to long

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Beverwijk, Holland
    Posts
    14
    How can I transform a hexadecimal string in a textbox to a long?
    Live Long and Prosper,

    Leo Schelvis
    [ECH]

    VB6

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Beverwijk, Holland
    Posts
    14

    No

    When I now use a letter in the textbox (A to F), I get an error type mismatch.

    What can I try else?
    Live Long and Prosper,

    Leo Schelvis
    [ECH]

    VB6

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Talking Use the val() function

    Here is one way:
    Code:
    Function HexToLong(ByVal sHex As String) As Long
        HexToLong = Val("&H" & sHex & "&")
    End Function
    Of course this assumes that the value doesn't have the "&H" before it and the "&" after it. If the value in the text box already has these VB pre- and post-fixes to the number, then you can just do this:
    Code:
    MyLong = Val(Text1.Text)
    Here's an article about this on MSDN (a most valuable resource).

    Hope that helps!
    ~seaweed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width