Results 1 to 8 of 8

Thread: How to convert hex to ascii?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    1

    How to convert hex to ascii?

    I'm a newbie, and learn vb6. I have a form with txtHex as input text, txtAscii as output and a button cmdConvert. How to make the code to convert from hex to ascii according to the form? Thx 4 your help..

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to convert hex to ascii?

    Thread moved from the 'CodeBank VB6' forum (which is for you to post your code examples, not questions) to the 'VB6' forum

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to convert hex to ascii?

    Welcome to the forums.

    ASCII pertains to text (i.e., characters). Hex pertains to numbers.
    To convert Hex to a number, use the Val() function and precede the hex with the &H prefix.
    Val(&HFF) = 255 and Hex(255) = "FF"
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: How to convert hex to ascii?

    but LaVolpe once i tried hex in vb its totally messed up, hex in vb is not red green blue, its blue green red.
    for example FF0000 will be displayed as blue and 0000FF will be red...

    by the way, decimal of hex could be converted with the windows calculator..

    http://www.vbforums.com/showthread.php?t=231962

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to convert hex to ascii?

    Quote Originally Posted by Justa Lol View Post
    but LaVolpe once i tried hex in vb its totally messed up, hex in vb is not red green blue, its blue green red.
    for example FF0000 will be displayed as blue and 0000FF will be red...

    by the way, decimal of hex could be converted with the windows calculator..

    http://www.vbforums.com/showthread.php?t=231962
    Because &HFF0000 is Blue and &H0000FF is Red. Do you doubt me?
    Code:
    MsgBox "Blue: " & vbBlue & " " & &HFF0000
    MsgBox "Red: " & vbRed & " " & &H0000FF
    The VB Hex function works perfectly, i.e., Val(&H0000FF)=vbRed & Hex(vbRed)="FF"

    If whatever app you are using needs the hex displayed in reverse order, it is up to you to reverse it. If you are trying to extract RGB values from a bitmap, know the bitmap structure as most are BGR, not RGB.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: How to convert hex to ascii?

    well that means its wrong with the hex code you use in any other language.

    how come that its the opposite in any website programming language or java for example?

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to convert hex to ascii?

    Quote Originally Posted by Justa Lol View Post
    well that means its wrong with the hex code you use in any other language.
    how come that its the opposite in any website programming language or java for example?
    Maybe Java is backwards.
    Open the scientific calculator (calc.exe) in Hex mode and enter in FF0000 and convert that to decimal and you will get a return value of 16711680 (vbBlue). It doesn't really matter which is backwards and which is not, it only matters that you know what format the app requires.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: How to convert hex to ascii?

    well now i understand why...

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