Results 1 to 5 of 5

Thread: hex to ascii or ansi(Resolved)

  1. #1

    Thread Starter
    Lively Member dedub's Avatar
    Join Date
    Dec 2002
    Location
    NC
    Posts
    98

    hex to ascii or ansi(Resolved)

    I have browsed for an hour on this and have not found much. All the code snippets would work but right not Im not interested on calling a function. What I would like to do is simply type a two digit hex into a text box and get the ascii or ansi equivelent. Here is what I have so far. Oh, it does work until you introduce a letter from the alphabet, then it crashes.
    VB Code:
    1. Private Sub Command2_Click()
    2. Dim num As Long
    3. num = Text1.Text
    4. Text2.Text = Chr(Val(num))
    5. End Sub
    Any help would be great
    Last edited by dedub; Jun 3rd, 2005 at 10:25 PM. Reason: Resolved
    R.L.T.W. A+, NET+, CCNA

    Doin' my best

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: hex to ascii or ansi

    Look at this: If you want more than one character, separate them with a space each, so they can be split.


    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   MsgBox HexToString("50 50 52 40 FF")
    5. End Sub
    6.  
    7. Function HexToString(ByVal sText As String) As String
    8.     Dim saHex() As String, i As Long
    9.     saHex = Split(sText)
    10.     For i = 0 To UBound(saHex)
    11.         HexToString = HexToString & ChrW("&H" & saHex(i))
    12.     Next
    13. End Function

  3. #3

    Thread Starter
    Lively Member dedub's Avatar
    Join Date
    Dec 2002
    Location
    NC
    Posts
    98

    Re: hex to ascii or ansi

    dglienna, great code and I understand it 100%. There were dozens of similar examples but again, a function is being called, there is a for next loop and a slight parse with the split. There has to be an easier way to just take 2 hex numbers, convert them and put them in a text box. Sorry, call me a simpleton
    R.L.T.W. A+, NET+, CCNA

    Doin' my best

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: hex to ascii or ansi

    Simple enough? Mytext is where you type and text1 is where you get the converted string. Add a command button called command1 so that you can play around with it.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.   Text1.Text = ChrW("&H" & MyText.Text)
    5. End Sub

  5. #5

    Thread Starter
    Lively Member dedub's Avatar
    Join Date
    Dec 2002
    Location
    NC
    Posts
    98

    Re: hex to ascii or ansi

    That's it!!! Bingo. You are the Man. Thanks!

    ds
    R.L.T.W. A+, NET+, CCNA

    Doin' my best

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