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..

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.