473,385 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

True & False!

<%
If(False) Then
Response.Write("False")
Else
Response.Write("True")
End If
%>

In the above code, the Else condition will be executed. Why?

Thanks,

Arpan

Jul 22 '05 #1
11 2421
Arpan wrote:
<%
If(False) Then
Response.Write("False")
Else
Response.Write("True")
End If
%>

In the above code, the Else condition will be executed. Why?

Because it's False
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #2
Because Boolean conditions always default to True. For example;

<%
Dim blnRet
If blnRet <> False Then Response.Write "blnRet is " & blnRet &
"<br><br>"
blnRet = False
If blnRet <> True Then Response.Write "blnRet is " & blnRet
%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"Arpan" <ar******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
<%
If(False) Then
Response.Write("False")
Else
Response.Write("True")
End If
%>

In the above code, the Else condition will be executed. Why?

Thanks,

Arpan

Jul 22 '05 #3
Because the "if block" of an if-then-else construct is executed when the if
statements expression is true. False is never true so the "else block" will
always be executed.

--
--Mark Schupp
"Arpan" <ar******@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
<%
If(False) Then
Response.Write("False")
Else
Response.Write("True")
End If
%>

In the above code, the Else condition will be executed. Why?

Thanks,

Arpan

Jul 22 '05 #4
"Steven Burn" wrote in message news:ev**************@TK2MSFTNGP09.phx.gbl...
: Because Boolean conditions always default to True. For example;
:
: <%
: Dim blnRet
: If blnRet <> False Then Response.Write "blnRet is " & blnRet &
: "<br><br>"
: blnRet = False
: If blnRet <> True Then Response.Write "blnRet is " & blnRet
: %>

I think you got that backwards.

The initial Boolean value for the new object. If Boolvalue is omitted, or is
false, 0, null, NaN, or an empty string, the initial value of the Boolean
object is false. Otherwise, the initial value is true.

--
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
Jul 23 '05 #5
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?

Thanks once again to all of you,

Regards,

Arpan

Jul 24 '05 #6
0 generally =True/Success, 1 generally = False/Failure

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"Arpan" <ar******@hotmail.com> 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?

Thanks once again to all of you,

Regards,

Arpan

Jul 24 '05 #7
hehe Roland, knew I'd feck something up somewhere ;o) (usually do)(cheers
for the correction)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Roland Hall" <nobody@nowhere> wrote in message
news:e4**************@TK2MSFTNGP14.phx.gbl...
"Steven Burn" wrote in message news:ev**************@TK2MSFTNGP09.phx.gbl... : Because Boolean conditions always default to True. For example;
:
: <%
: Dim blnRet
: If blnRet <> False Then Response.Write "blnRet is " & blnRet &
: "<br><br>"
: blnRet = False
: If blnRet <> True Then Response.Write "blnRet is " & blnRet
: %>

I think you got that backwards.

The initial Boolean value for the new object. If Boolvalue is omitted, or is false, 0, null, NaN, or an empty string, the initial value of the Boolean
object is false. Otherwise, the initial value is true.

--
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

Jul 24 '05 #8
"Steven Burn" wrote in message
news:ex****************@TK2MSFTNGP09.phx.gbl...
: hehe Roland, knew I'd feck something up somewhere ;o) (usually do)(cheers
: for the correction)

I dunno Steven. I think I'm shock and you're awe. I wait patiently for the
times when the masters miss one. (O;=

--
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
Jul 24 '05 #9
"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
Jul 24 '05 #10
hehe, good job I'm no master <g>, prolly be worse than I already am :o\

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Roland Hall" <nobody@nowhere> wrote in message
news:er**************@TK2MSFTNGP10.phx.gbl...
"Steven Burn" wrote in message
news:ex****************@TK2MSFTNGP09.phx.gbl...
: hehe Roland, knew I'd feck something up somewhere ;o) (usually do)(cheers : for the correction)

I dunno Steven. I think I'm shock and you're awe. I wait patiently for the times when the masters miss one. (O;=

--
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

Jul 24 '05 #11
> "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?


The definition of a "true" expression is one that returns a non-zero value.
From the docs for CBool():

If expression is zero, False is returned; otherwise, True is returned. If
expression can't be interpreted as a numeric value, a run-time error occurs.

Try this for fun:
response.write CLng(true)
response.write CLng(false)
--
Mark Schupp
Jul 25 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: Scott Chapman | last post by:
There seems to be an inconsistency here: Python 2.3.2 (#1, Oct 3 2003, 19:04:58) on linux2 >>> 1 == True True >>> 3 == True False >>> if 1: print "true" ....
3
by: drs | last post by:
I just upgraded my Python install, and for the first time have True and False rather than 1 and 0. I was playing around at the command line to test how they work (for instance, "if 9:" and "if...
35
by: Steven Bethard | last post by:
I have lists containing values that are all either True, False or None, e.g.: etc. For a given list: * If all values are None, the function should return None.
15
by: F. Da Costa | last post by:
Hi all, Following two sniperts of code I'm using and getting very interesting results from. ..html <tr id="1" class="segment" open="false"> This is the segment under 'investigation' ..js
14
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a...
48
by: Skybuck Flying | last post by:
Hi, I came across this C code which I wanted to understand etc it looked like this: if (-1) etc It made me wonder what the result would be... true or false ? In C and Delphi
17
by: orekinbck | last post by:
Hi There Say I want to check if object1.Property1 is equal to a value, but object1 could be null. At the moment I have code like this: if (object1 != null) { if (object1.Property ==...
2
by: Kristof Taveirne | last post by:
Hi, I'm developing an application on PDA using WindowsCE. In my application I have several tabs at the bottom of my screen. However, in one of the tabs I've placed 2 radiobutton, used to switch...
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.