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

If then not working

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
This seems like it should woork but is not:

I am finding two variable, say var1 and var 2, I then do:

...if var1 = var2 Then%>
...display a certain image...
<%Else%>
...display another image...
<%End If....

it only displays one image no matter what. I know they variables are getting created/grabbed correctly. When I change the = to <> it shows the other image, so it is working in some sense but not as it should.

Does anything leap out as being wrong?
 
Before the IF statement add this code:
msgbox(&quot;var1=&quot; & var1 & chr(10) & &quot;var2=&quot; & var2)

When you run the script, what does the message say?
 
the test sfvb is having you do is to see if you have values in the variables.

what is apparently happening is a condition being the else is always being met, in turn the variables may not be set the way you think they are. You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
I have response.written the variables and I know that they are correct.... ????
 
what is contained in the variables..I mean what are you comparing
if this is equal to this
are these strings?

There's nothing wrong with your if statement. There is however something wrong in what your comparing and either or how your comparing it but with the limit of info there's not much direction for us to go. no what I mean You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
var1 is grabbed via a request.QueryString and var 2 is 0 and then is changed via a while loop Could that be it? is it treating var 1 as a string and var 2 as an integer thus screwing up any comparison? if so, how do I change the string to an integer?- here it is at a greater scale:

<%
Dim var2
var 2 = 0;
While finder > 0
If var1 = var2 Then%>
...display a certain image...
<%Else%>
...display another image...
<%End If
finder = finder+1
var2 = var2+10
Wend
%>

Finder is a variable developed based on a number of records in a db
 
You can use the Cint function.

If Cint(var1) = var2 Then
 
easy way to find out is to use either the CStr function to convert both to a string or the CIng to convert both to a integer
<%
Dim var2
var 2 = 0;
While finder > 0
If CInt(var1) = CInt(var2) Then%>
...display a certain image...
<%Else%>
...display another image...
<%End If
finder = finder+1
var2 = var2+10
Wend
%>
You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
Excellent - thank you both - turning them into integers worked...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top