Bobofbobland
Programmer
Hi,
I'm using the API to open a socket and send and recieve data.
My code contains the following line and function:
send hTCPSocket, StripToAscii(bytLogin(), Len(strLogin) * 2), Len(strLogin), 0
Private Function StripToAscii(bytUnicode() As Byte, iLength As Integer) As Byte()
Dim iPos As Integer
Dim bytAscii() As Byte
ReDim bytAscii((iLength / 2) - 1)
For iPos = 0 To (iLength / 2) - 1
bytAscii(iPos) = bytUnicode(iPos * 2)
Next
StripToAscii = bytAscii
End Function
Sometimes I send Unicode, sometimes I send the Ascii using the function call above.
I'm reasonably sure that the byte array I pass to the send API call is correct. What I get at the other end though is gibberish - the correct number of bytes but values from Hell - some ascii, some not.
I'm new to VB and sockets and I just wondered if anyone could see anything glaringly wrong with my code.
Any help would be appreciated.
I'm using the API to open a socket and send and recieve data.
My code contains the following line and function:
send hTCPSocket, StripToAscii(bytLogin(), Len(strLogin) * 2), Len(strLogin), 0
Private Function StripToAscii(bytUnicode() As Byte, iLength As Integer) As Byte()
Dim iPos As Integer
Dim bytAscii() As Byte
ReDim bytAscii((iLength / 2) - 1)
For iPos = 0 To (iLength / 2) - 1
bytAscii(iPos) = bytUnicode(iPos * 2)
Next
StripToAscii = bytAscii
End Function
Sometimes I send Unicode, sometimes I send the Ascii using the function call above.
I'm reasonably sure that the byte array I pass to the send API call is correct. What I get at the other end though is gibberish - the correct number of bytes but values from Hell - some ascii, some not.
I'm new to VB and sockets and I just wondered if anyone could see anything glaringly wrong with my code.
Any help would be appreciated.