|
-
Jun 3rd, 2005, 09:32 PM
#1
Thread Starter
Lively Member
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:
Private Sub Command2_Click()
Dim num As Long
num = Text1.Text
Text2.Text = Chr(Val(num))
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
-
Jun 3rd, 2005, 09:42 PM
#2
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:
Option Explicit
Private Sub Form_Load()
MsgBox HexToString("50 50 52 40 FF")
End Sub
Function HexToString(ByVal sText As String) As String
Dim saHex() As String, i As Long
saHex = Split(sText)
For i = 0 To UBound(saHex)
HexToString = HexToString & ChrW("&H" & saHex(i))
Next
End Function
-
Jun 3rd, 2005, 09:58 PM
#3
Thread Starter
Lively Member
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
-
Jun 3rd, 2005, 10:19 PM
#4
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:
Option Explicit
Private Sub Command1_Click()
Text1.Text = ChrW("&H" & MyText.Text)
End Sub
-
Jun 3rd, 2005, 10:22 PM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|