Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

Sponsored Links

Discuss "If-Then Problem" in the ASP Development forum.

ASP Development - Learn coding practices and tips to get the best out of your Active Server Pages (ASP). The Classic ASP forum is for ASP/VBScript and ASP/JScript applications.


Closed Thread « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old April 7th, 2008, 01:35 PM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default If-Then Problem

If problem

--------------------------------------------------------------------------------

Hi,

I have 3 variables which store values like this

lunch="1"
dinner="2"
snacks="3"



if lunch is selected then the value is 1 if not its blank
if dinner is selected then the value is 2 if not its blank
if snacks is selected then the value is 3 if not its blank

If all 3 are selected the price is $12
if 2 of them is selected the price is $8
if one of them is selected the price is $5

so here is the code

Code:
If lunch="1" And dinner="2" And snacks="3" Then
	finaltotal="12"
End If

If (lunch="1" And dinner="2") or (lunch="1" And snacks="3") Or (dinner="2" And snacks="3") Then
	finaltotal="8"

End If

If (lunch="1") Or (dinner="2") Or (snacks="3")  Then
	finaltotal="5"
End If
but its not working any idea

todd
Sponsored Links
  #2  
Old April 7th, 2008, 01:38 PM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 143
Thanks: 10
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

need to use ElseIfs ... the way you have it now, is that you're going to go through each if/then statement ... hence you could change your variable value. try something like this:
Code:
If lunch="1" And dinner="2" And snacks="3" Then
	finaltotal="12"
ElseIf (lunch="1" And dinner="2") or (lunch="1" And snacks="3") Or (dinner="2" And snacks="3") Then
	finaltotal="8"
ElseIf (lunch="1") Or (dinner="2") Or (snacks="3")  Then	
             finaltotal="5"
End If
__________________
Quote of the Month:
Regret: It hurts to admit when you make mistakes - but when they're big enough, the pain only lasts a second.

Questions to Ponder:
Could it be that all those trick-or-treaters wearing sheets aren’t going as ghosts but as mattresses?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright © 2008 sbenj69
  #3  
Old April 7th, 2008, 01:54 PM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Any particular reason your variables need to be 1, 2 and 3 (and strings no less). If you can make it so that variable=1 if select, 0 if not, then this becomes a much easier problem by using a SELECT CASE.

Code:
SELECT CASE lunch+dinner+snacks  ' assume Int, otherwise convert
CASE 3 
  finaltotal = 12
CASE 2
  finaltotal = 8
CASE 1
  finaltotal = 5
CASE ELSE
  finaltotal = 0
END SELECT
In the event the values just have to be different, can you make it 1, 2 and 4? Then
Code:
SELECT CASE lunch+dinner+snacks  ' assume Int, otherwise convert
CASE 7 
  finaltotal = 12
CASE 3,5,6
  finaltotal = 8
CASE 1,2,4
  finaltotal = 5
CASE ELSE
  finaltotal = 0
END SELECT

Comments on this post
keep_it_simple agrees:
  #4  
Old April 30th, 2008, 05:35 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Due to inactivity of 14 days, this thread is deemed abandoned and is now closed. If this thread was marked as "Solved", the orginal poster may mark it as "Unsolved" via the Thread Tools menu, thus re-opening the thread. If this thread was not marked as "Solved", the original poster may re-open the thread via the Thread Tools menu.

Regards,

richyrich
DeveloperBarn Forums Moderator
Closed Thread

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 01:17 PM.



Content Relevant URLs by vBSEO 3.2.0