Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.
25% off Hosting at HostGator.com:
Use Code techbits25



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. 

So in the above code, a simple:

x = Int(x)

would have taken care of the problem.

 

blog comments powered by Disqus
Have your own Tech-bit to contribute? Submit it here

Other questions in this category:
I get this error runing asp scripts - Disallowed Parent Path. How can I fix this?
My asp scripts give me an Error 500 with no useful debugging information. How can I fix this?
What's this error mean: ActiveX component can't create object: 'EasyMail.SMTP' ?
Here's a simple captcha method for ASP:
I'm getting an error "ASP_0131 Disallowed_Parent_Path" trying to include an asp page



Powered by KnowledgebasePublisher 1.1
Host Gator
Content provided by Roberts WebForge, Inc.