Forum Moderators: open

Message Too Old, No Replies

Compaing Variables in ASP

         

Big_Perm

2:30 pm on Aug 6, 2001 (gmt 0)



Comparing a recordset object and a dim variable never returns true, even if I print the variables and they are the same. For example

Dim temp
temp = 'sometext'
If temp = objRS(0) Then
...

Where objRS(0) is text
Why doesn't this ever evaluate to true?

sugarkane

8:24 pm on Aug 6, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could it be to do with data types? Does it make any difference if you do something like

temp2 = objRS(0)
if temp = temp2 then
..

?

cyril kearney

5:27 pm on Aug 8, 2001 (gmt 0)

10+ Year Member



Dim temp
temp = 'sometext'
If temp = objRS(0) Then

If temp = Trim(objRS(0)) Then

The text in objRS(0) probably has trailing spaces. 'sometext' and 'sometext ' would not be equal.

Cyril Kearney
<snip> Sorry, no sigs - Sugarkane

(edited by: sugarkane at 5:31 pm (gmt) on Aug. 8, 2001

sugarkane

5:48 pm on Aug 8, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld Cyril.

Thanks for the answer. Is objRS(0) a fixed length field or something and so padded with the trailing spaces?

My ASP is very shakey BTW ;)

Xoc

8:27 pm on Aug 10, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Realize that objRS(0) is a shorthand for objRS.Fields.Item(0).Value. So you are comparing that to the value of the first field of the RecordSet. Generally, you are better off using the field name, as in objRS.Fields.Item("CustomerID").Value.

Also, for VBScript, you have to use double quotes, as in:

temp = "sometext"

Big_Perm

11:03 am on Aug 13, 2001 (gmt 0)



Using Trim() solved the problem, thanks.