Results 1 to 3 of 3

Thread: string problems with winsock

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    2

    string problems with winsock

    Hi all,

    I´m sending data to the PC from an embedded application. The data contains a string (node name, MAC address) and some user data. The string contains only ascii characters, but the data can be anything from 0 to 0xFF (255). I have been converting the string to a variable (int) in VB by doing Asc(mid(strData, 19,1)) which works fine in Germany. But, if the codepage is different it doesn´t work anymore, all sorts of strange things happen. I even get the wrong value from Len(strData) somehow. e.g. in:

    Private Sub wsRunning_DataArrival(ByVal bytesTotal As Long)
    On Error GoTo error
    wsRunning.GetData strData, vbString

    Now bytesTotal is 43 (which is the amount of bytes sent, so correct), but Len(strData) returns 42..... possibly because of illegal characters?

    Anyway, I am freaked by this... I tried CInt(Mid(strData,18,1)) but only get type mismatch errors..... help!!!!

    thanks... any suggestions would be greatly appreciated!

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: string problems with winsock

    Try something like this:
    Code:
    Private Sub wsRunning_DataArrival(ByVal bytesTotal As Long)
        Dim DataArr() As Byte
        Dim strData As String
        
        On Error GoTo Error
        wsRunning.GetData DataArr, vbArray + vbByte, bytesTotal
        
        strData = StrConv(DataArr, vbUnicode)
    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Re: string problems with winsock

    Problem solved!
    Now it is:

    ReDim wsRunningData(48)
    wsRunning.GetData wsRunningData, vbArray + vbByte, 48

    Since I know the expected data string is either 43 or 48 bytes, I limited the max amount of data to this.

    Then I can convert one part of the array to a string:

    For i = 0 To 2
    strDataVisual = strDataVisual & Chr(wsRunningData(i))
    mask = mask + Chr(wsRunningData(i))
    Next

    The rest is just used as an array of bytes.

    Thanks for your help!

    jeroen

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