"Arpan" wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
: Thanks, mates, for your inputs. In the following 2 sample codes, the
: first example executes the 'If' condition whereas the second example
: executes the 'Else' condition.
:
: Code 1:
: ----------------------------------------------
: <%
: If(1) Then
: Response.Write("True")
: ElseIf(0) Then
: Response.Write("False")
: End If
: %>
: ----------------------------------------------
:
: Code 2:
: ----------------------------------------------
: <%
: If(0) Then
: Response.Write("True")
: ElseIf(1) Then
: Response.Write("False")
: End If
: %>
: ----------------------------------------------
:
: Why?
I'm winging this answer...
I think that's because both are equal to a value, so both are true. You
weren't testing a variable to see if it was equal to a value.
If somevariable = 0 then
....and unless you assigned a value to it, no matter what value you tested
against it, it would be false. Variables in ASP VBScript are variants. In
other words, they vary depending on how you assign them.
Since you cannot assign a number as a variable, a number alone is a value
and cannot be tested as boolean.
Ok, now I'm cheating...
MSFT says:
Naming Restrictions
Variable names follow the standard rules for naming anything in VBScript. A
variable name:
a.. Must begin with an alphabetic character.
b.. Cannot contain an embedded period.
c.. Must not exceed 255 characters.
d.. Must be unique in the scope in which it is declared.
To test what variable subtype a variable is, use varType(variable)
wscript.echo varType(0) will return 2, which is an integer, so 1 could also
return 2, since it is also an integer.
To find out what type of variable it ss, use typename(variable) to get a
verbose return.
wscript.echo typename(0) returns Integer.
So, it's not boolean which is probably why it returns true for both.
VarType Constants
Constant Value Description
vbEmpty 0 Uninitialized (default)
vbNull 1 Contains no valid data
vbInteger 2 Integer subtype
vbLong 3 Long subtype
vbSingle 4 Single subtype
vbSingle 5 Double subtype
vbCurrency 6 Currency subtype
vbDate 7 Date subtype
vbString 8 String subtype
vbObject 9 Object
vbError 10 Error subtype
vbBoolean 11 Boolean subtype
vbVariant 12 Variant (used only for arrays of variants)
vbDataObject 13 Data access object
vbDecimal 14 Decimal subtype
vbByte 17 Byte subtype
vbArray 8192 Array
Typename Return Values
Value Description
Byte Byte value
Integer Integer value
Long Long integer value
Single Single-precision floating-point value
Double Double-precision floating-point value
Currency Currency value
Decimal Decimal value
Date Date or time value
String Character string value
Boolean Boolean value; True or False
Empty Unitialized
Null No valid data
<object type> Actual type name of an object
Object Generic object
Unknown Unknown object type
Nothing Object variable that doesn't yet refer to an object instance
Error Error
--
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