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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with this code please...

Status
Not open for further replies.

Vermontecher

Programmer
Feb 13, 2005
14
0
0
US
Hi All,
I am having a tough time with something that I figured (once again erroneously) would be quite simple. I want to compare two variables, one in a querystring and one in the database. I have the following which, when the page displays, shows me the two variables side by side. The problem is the if statement always returns false even when the values match exactly. Does anyone have a suggestion as to why it would not return true if the two numbers match exactly? I am trying to find the exact match between the querystring and the sort order for the record in the database. If they match I want one thing to happen if they don't I want something else to happen for all unmatched records.



<%
Dim SOrder, SKey
SOrder=rs("SortOrder")
Response.Write (Sorder)
SKey=Request.QueryString("current")
Response.Write (SKey)
If ("SOrder") = ("SKey") Then
Response.Write ("True")
Else
Response.Write ("False")
End If
%>


Thanks
JW
 
tt][blue]
If ("SOrder") = ("SKey") Then[/blue][/tt]

Since you have SOrder and SKey withing quotes, you are comparing those strings. Since they are ALWAYS going to be different, you will always get "False".

What you really want to do is to compare the values contained within variables. To do that, you need to remove the quotes. (and the parenthesis are not needed either).

[tt][blue]If SOrder = SKey Then[/blue][/tt]

Also, since this is ASP land, and all variables are variants, you may want to trim the SKey (from the query string), like this...


Code:
<%
Dim SOrder, SKey
SOrder=rs("SortOrder")
Response.Write (Sorder)
SKey=[!]Trim([/!]Request.QueryString("current")[!])[/!]
Response.Write (SKey)

If SOrder = SKey Then
  Response.Write ("True")
Else
  Response.Write ("False")
End If
%>

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks George,
I just had to change the code as follows and it worked wonders. I really appreciate the prompt reply.

<%
Dim SOrder, SKey
SOrder=Trim(rs("SortOrder"))
Response.Write (Sorder)
SKey=Trim(Request.QueryString("current"))
Response.Write (SKey)

If SOrder = SKey Then
Response.Write ("True")
Else
Response.Write ("False")
End If
%>

SOrder needed to have Trim as well.

Thanks again,
JW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top