0

Dear sir,
I am getting some port input in ASCII form, and wanted to convert it in HEX form, I have used following code

'\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////
For A = 1 To Len(sText)
    HexIt = HexIt & Hex$(Asc(Mid(sText, A, 1))) & Space$(1)
    On Error Resume Next
    DoEvents
Next A
HexIt = Mid$(HexIt, 1, Len(HexIt) - 1)
'\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////

but some time it gives me wrong value in HEX. please suggest any other code..

Edited by Reverend Jim: Reformatted code

2
Contributors
1
Reply
15
Views
2 Years
Discussion Span
Last Post by Minimalist
0

You need two textboxes and a button. Add a module to your project and copy:

Option Explicit

Public Function HexIt(sText As String) As String
Dim A As Long
For A = 1 To Len(sText)
HexIt = HexIt & Hex$(Asc(Mid(sText, A, 1))) & Space$(1)
On Error Resume Next
DoEvents
Next A
HexIt = Mid$(HexIt, 1, Len(HexIt) - 1)
End Function

and in the command button on the form you need to put:

Private Sub Command1_Click()
Dim txtAscii As String
txtAscii = Text1
If Len(txtAscii) > 0 Then
    txtHex = HexIt(txtAscii)
    Text2 = txtHex
End If
End Sub

Please do check the answer for correctness

Edited by Minimalist

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.