Variable smaller than question.

M

Miguel Orrego

Hi,

Can somebody tell me why when I run this code i get this result?

<%
If Available < Requested then

Response.Write "Available = "&Available&"<BR>"
Response.Write "Requested = "&Requested

Else

blah blah blah

End If
%>

Result:

Available = 5
Requested = 2

It's clear that Available is not smaller than Requested so why is it
response.writing instead of doing blah blah blah?

Is my syntax horribly wrong or something?

Help Appreciated. Thanks.
 
R

Roland Hall

:
: <%
: If Available < Requested then
:
: Response.Write "Available = "&Available&"<BR>"
: Response.Write "Requested = "&Requested
:
: Else
:
: blah blah blah
:
: End If
: %>
:
: Result:
:
: Available = 5
: Requested = 2
:
: It's clear that Available is not smaller than Requested so why is it
: response.writing instead of doing blah blah blah?
:
: Is my syntax horribly wrong or something?

Miguel...

Put this right under <%@ LANGUAGE=VBScript %>
<% Option Explicit %>

If you typed your code in here, perhaps in your code there is a typo for
Available.
Option Explicit requires that you (Dim)ension all variables so if you have a
typo, it will tell you.
Also, put a space on either side of & so you do not have a problem with hex
values &h and so it is easier to read.

<%@ LANGUAGE=VBScript %>
<%
Option Explicit

Dim Available, Requested
Available = 5
Requested = 2

If Available < Requested then
Response.Write "Available = " & Available & "<BR>"
Response.Write "Requested = " & Requested
Else
'blah blah blah
End If
%>

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
C

Chris Barber

More likely that the < operator is comparing string to string.

So try this:

<%
If IsNumeric(Available) and IsNumeric(Requested) Then
If CDbl(Available) < CDbl(Requested) then
Response.Write "Available = " & Available & "<BR>"
Response.Write "Requested = " & Requested
Else
'blah blah blah
End If
Else
Response.Write "One or more of the variables are *not* numeric"
End if
%>

Also remember to use spaces around the ampersand (concatenation) operator.

Hi,

Can somebody tell me why when I run this code i get this result?

<%
If Available < Requested then

Response.Write "Available = "&Available&"<BR>"
Response.Write "Requested = "&Requested

Else

blah blah blah

End If
%>

Result:

Available = 5
Requested = 2

It's clear that Available is not smaller than Requested so why is it
response.writing instead of doing blah blah blah?

Is my syntax horribly wrong or something?

Help Appreciated. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,372
Latest member
LucretiaFo

Latest Threads

Top