Home / Programming / ASP / My asp conditional statements are not working - what's going on?
My asp conditional statements are not working - what's going on?
Last updated: 06/27/2009
I ran into this type of situation programming asp, and was puzzled for a short time:
Response.Write("x = "&x)
if x = 1 Then
response.write ("HELLO")
End If
The value of "x" seemed to be 1, but the conditional was not firing. I was baffled. I realized that years of perl / php
programming had spoiled me! VBscript is strongly typed, and doesn't (apparently) automatically convert your variables to the right type. So "x" in this case was "1" (a string) rather than 1 (an integer).
The solution is to pay attention to your types, and use the "Int" function to cast the the variable, or set it directly to the right type.