Question

I faced with unexpected difficulty while trying to compare two variables:

First variables comes from XML:

For i = 0 To UBound(array, 2)
    If Bk  = array(0, i) Then
       Book= cstr(array(1, i))
      Exit For
    End If
Next

Imagine Book = "LONDON"

Second variables (SQLBook) comes from SQL select and if to use WATCH in QTP var BOOK and SQLBOOK are equal visually, but if we compare them via LEN(): BOOK has 8 length (len(Book)) and SQLBook has 9 lenght.

Could you please advise what is wrong?

Was it helpful?

Solution

There could be a space or some invisible character in the SQLBook. To find out the difference between the two variables do the following:

1) First remove the similar characters:

Dim diff AS String = Replace(SQLBook, BOOK, "")

2) Then check the ASCII code of the character left in diff:

Debug.Print Asc(diff)

EDIT As per your comment, the difference is a Carriage Return character which is used to make a new line. To get rid of it, use:

Replace(SQLBook, vbCr, "")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top