I want to send some packets they are in hex format
01 00 00 00 AA 00 00 00 01
because how winsock works i first need to convert it to ascii right?
how could i do that every time i try it looses the NULLS - 00
help would be appreciated thanks...

using vb6 btw
this is the script i use to convert hex to ascii

Private Function HexToString(Value As String)
    Dim szTemp As String
    szTemp = Value
    
    Dim szData As String
    szData = ""
    While Len(szTemp) > 0
        szData = Chr(CLng("&h" & Right(szTemp, 2))) & szData
        If (Len(szTemp) = 1) Then
            szTemp = Left(szTemp, Len(szTemp) - 1)
        Else
            szTemp = Left(szTemp, Len(szTemp) - 2)
        End If
    Wend
    HexToString = szData
End Function

Try the following (shorter) version to convert your hex to ascii -

Public Function hex2ascii(ByVal hextext As String) As String
    
For y = 1 To Len(hextext)
    num = Mid(hextext, y, 2)
    Value = Value & Chr(Val("&h" & num))
    y = y + 1
Next y

hex2ascii = Value
End Function

In your form it can be called -

Text1.Text = hex2ascii (TheHexValueHere)

thanks for reply error variable not defined then it highlights "y" where y = 1

nvm the above post code works great only thing is when i insert
01 00 00 00 AA 00 00 00 01
it adds more than the correct amount of nulls
butif i enter it like
01000000AA00000001
without spaces then it outputs the correct value

error variable not defined then it highlights "y" where y = 1

My apologies, add the following BEFORE the code is executed -

Dim y As Integer

nvm the above post code works great only thing is when i insert
01 00 00 00 AA 00 00 00 01
it adds more than the correct amount of nulls
butif i enter it like
01000000AA00000001
without spaces then it outputs the correct value

That is because it reads the empty space as a zero. Remove all the spaces first and then run the conversion -

Text1.Text = Replace(Text1.Text," ","")

Thanks everything working perfectly now

Its only a pleasure. Happy coding.:)

Ow yeah fixed problem by putting the output into a string then sending it straight from the string...
bec bedfore i stored the converted ascii into a textbox then send it from there but turns out that doesnt work too well :D

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.