Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing ANSI 'string' with data returned in long varchar 1

Status
Not open for further replies.

avanderlaan

Programmer
Jul 11, 2002
156
I need to compare data coming from a serial port returned by a COM object as a VARIANT array of bytes with data stored in a long varchar column in SQL Server.

When I return the data in an ADO recordset and compare it with the serial data in C++ the data is identical. When I return the array of bytes to VB and compare it with the recordset data it does not compare although I can "see" that the "strings" are equivalent.

I have tried StrCmp between the byte array and rs("item").value, and I have tried CopyMemory to move the rs("item").value into a second byte array.

Thanx for any help or suggestions.
 
Here's a guess: try
Code:
CStr(ByteArray)
before comparing it to the recordset data.

HTH,
David
 
Does the string have an ending Null Char.

I would suggest pringting both to the debug window to see...

Debug.Print

Craig, mailto:sander@cogeco.ca

In the computer industry, there are three kinds of lies:
lies, damn lies, and benchmarks.
 

perhaps...
[tt]
Dim S As String, B() As Byte
S = "This is a test"
B = StrConv(S, vbFromUnicode)'from string to byte array
S = StrConv(B, vbUnicode)'from byte array to string
[/tt]

Good Luck

 
Thank you all. This was almost an instant solution.

Dim aString as String
aString = StrConv(bytes, vbUnicode)
If (aString = rs("item")) Then
' do stuff
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top