Reply
How to evaluate 2 expressions?
Old 05-24-2007, 05:41 PM How to evaluate 2 expressions?
webgrrl's Avatar
Skilled Talker

Posts: 71
I am trying to evaluate 2 expressions. What is the best way to do this?

Could I use an If...Then statement, like this?
If (FirstVar >= 1) AND (FirstVar <= 500) Then
Response.Write "The first variable is fairly small"
End If
Can I use a Do...While statement, like this?
Do While (varCounter <= FirstVar) AND (FirstVar <= 500)
varCounter = varCounter + 100
Loop
If these are not good, then what should I use instead? Please help!

Thanks,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-24-2007, 06:04 PM Re: How to evaluate 2 expressions?
ExpressoDan's Avatar
Ultra Talker

Posts: 317
Name: This Space for Rent
Location: Georgia
It depends on what you want to evaluate and the amount of variables your trying to evaluate. Can you be a little more specific?

Either example there could work, but it depends on what you're trying to do.
__________________
Daniel
"I think therefore I am, I think." <!-- George Carlin
ExpressoDan is offline
Reply With Quote
View Public Profile Visit ExpressoDan's homepage!
 
Old 05-24-2007, 06:26 PM Re: How to evaluate 2 expressions?
webgrrl's Avatar
Skilled Talker

Posts: 71
I'm trying to see if a number is between two numbers. I realize that I can only evaluate one expression at a time (i.e., I know that I can't do this: y > z > 4).

My asp book says that If...Then statements can only evaluate one expression, but the code seems to work, so I am wondering if the code is inefficient? Is there a better way to evaluate 2 expressions?

Thanks,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 05-25-2007, 12:18 PM Re: How to evaluate 2 expressions?
chrishirst's Avatar
Super Moderator

Posts: 13,474
Location: Blackpool. UK
The first example would be efficient

an IF statement can only evalute a single expression but as you can see expressions can be joined with logical operators (AND, OR, XOR) and paranthesis can be used for the evaluation order

it's ((y > z) and (z > 4)) BTW If my boolean algebra is up to speed
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-25-2007, 06:36 PM Re: How to evaluate 2 expressions?
webgrrl's Avatar
Skilled Talker

Posts: 71
Ahhh, thank you, good to know.

WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 05-26-2007, 03:50 PM Re: How to evaluate 2 expressions?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
You don't need the brackets at all in your particular if statement, as in most if statements. The only time you need them is if you're comparing using different logical operators and you need to group them.

For example:

if FirstVar >= 1 and FirstVar <= 500 then

would be sufficient.

However, let's say you wanted to see if your number fell within one of two ranges:

if FirstVar >=1 and FirstVar <=500 or FirstVar >= 1000 and FirstVar <=5000 then

That wouldn't work because it would look for a number that was at least 1000 and no more than 500. There's no such animal.

That's where you need the brackets.

if (FirstVar >=1 and FirstVar <=500) or (FirstVar >=1000 and FirstVar <=5000) then

This would search for a number that's either between 1 and 500 or between 1000 and 5000.

This is rather abstract and confusing at first, but once you use the brackets a few times it will make some sense.
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-03-2007, 10:33 PM Re: How to evaluate 2 expressions?
Novice Talker

Posts: 13
Use the IF statement. Do-WHILE is for looping and what you have it not a loop.
brucec is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to evaluate 2 expressions?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13876 seconds with 12 queries