Results 1 to 6 of 6

Thread: Sending Hex through Winsock

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    13

    Question

    Does anyone know how to send "hex" through winsock? E.g. Something like...
    Code:
    HexData = 00 01 81 80 00 01 00 01 00 03 00 03 05 6C 6F 67
    Winsock1.Senddata HexData
    Or perhaps a function could help... such as...
    Code:
    Private Function EnHex(Hex as String)
    'How could I code this?
    End Function
    
    Winsock1.Senddata EnHex("00 01 81 80 00 01 00 01 00 03 00 03 05 6C 6F 67")
    Thanks. An example would be great.

  2. #2

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    13

    Question Also, another question

    How do you convert hex into string? That's another question I have. Thanks.

  3. #3
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    Hi,

    I think you got some thinking to do here...

    An HEX value is nothing diferent than an ASCII value, it's just the way YOU as a programmer see it in the variable.

    Suppose you want to send these values to you socket

    00 01 81 80

    Winsock1.Senddata Chr(0) & chr(1) & chr(&h81) & chr(&h80)...

    or you could have done this (which is exactly the same)

    Winsock1.Senddata Chr(0) & chr(1) & chr(129) & chr(128)...

    What you will receive in your winsock receive event is a string having unreadable caracters in it (little bars).
    To have the value of this you must MID then ASC each of
    the caracters one by one. value = asc(mid(str,1,1))

    Perhaps I didn't understand your question but just I replied
    just in case...

    Bye

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    13

    Cool Thanks a lot!

    I am pretty new to hex values and I didn't know that they weren't ascii values. That helps me tremendously. Thanks!

  5. #5
    New Member
    Join Date
    Mar 2000
    Posts
    3

    Question How about something like 6F?

    How could you convert something like 6F into a Chr()?

  6. #6
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Code:
    Dim sHex as String
    Dim sAscii as String
    
    sHex = "6F"
    
    sAscii = Chr(CInt("&h" & sHex))
    
    MsgBox "The Ascii Value for " & sHex & " is (" & sAscii & ")"
    In Visual Basic the value "&h" indicates a hex value. If you convert a string (where only numbers 0 to 9 and letters a to f are included) that has this at the front of it into an integer you get the equivalent ASCII value.

    I would be VERY cautious of this however as any ASCII value < 32 could give you a control code and would give you strange results of ever displayed.

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