![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| 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 todd |
| Sponsored Links |
|
#2
| ||||
| ||||
| 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
| ||||
| ||||
| 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 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 |
|
#4
| ||||
| ||||
| 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 |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|