Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
KennyR
- Posts: 256
- Joined: Thu Jan 19, 2012 4:25 am
Post
by KennyR » Thu Feb 14, 2013 2:23 am
Hi...noob question here, but I have tried this multiple ways and have no answer on how to structure my if/else statement without it verifying one of the 4 conditions and moving to the "else" statement. Here is my script and I'll explain...
Code: Select all
if vTS is not 0
then answer "Trauma Supplies missing from inventory. Please go back and complete Trauma section"
if vWhite is not 0
then answer "ALS supplies missing from inventory. Please go back and complete ALS section"
if vMisc is not 0
then answer "Miscellaneous Supplies missing from inventory. Please go back and complete Miscellaneous section"
if vAirway is not 0
then answer "Airway supplies missing from inventory. Please go back and complete Airway section"
else
put "Currently Stocked Items" & cr & fld "iot" card "Send" & cr & cr & "Items Needing Re-stocked" & cr & fld "not" card "Send" into vBody
mobileComposeMail "Test E-mail", someEmail@verizon.net,,, vBody, tAttachment
end if
end mouseUp
I want to check that all 4 conditions are true before triggering the "ELSE" statement, but what seems to happen is that as long as one condition is true, it goes to the "ELSE" statement instead of stopping. I have tried to make this into a "Switch" but I have the same issue....any ideas on what I am doing wrong??
-
magice
- Posts: 457
- Joined: Wed Mar 18, 2009 12:57 am
Post
by magice » Thu Feb 14, 2013 2:50 am
try this
Code: Select all
on mouseUp
if vTS is not 0
then
answer "Trauma Supplies missing from inventory. Please go back and complete Trauma section"
exit mouseUp
end if
if vWhite is not 0
then
answer "ALS supplies missing from inventory. Please go back and complete ALS section"
exit mouseUp
end if
if vMisc is not 0
then
answer "Miscellaneous Supplies missing from inventory. Please go back and complete Miscellaneous section"
exit mouseUp
end if
if vAirway is not 0
then
answer "Airway supplies missing from inventory. Please go back and complete Airway section"
exit mouseUp
end if
put "Currently Stocked Items" & cr & fld "iot" card "Send" & cr & cr & "Items Needing Re-stocked" & cr & fld "not" card "Send" into vBody
mobileComposeMail "Test E-mail", someEmail@verizon.net,,, vBody, tAttachment
end mouseUp
-
KennyR
- Posts: 256
- Joined: Thu Jan 19, 2012 4:25 am
Post
by KennyR » Thu Feb 14, 2013 2:57 am
AHHH! Never considered the "Exit MouseUp"
Thanks for the help!
-
magice
- Posts: 457
- Joined: Wed Mar 18, 2009 12:57 am
Post
by magice » Thu Feb 14, 2013 3:07 am
I believe you could also do it this way and it would be closer to the way you were trying to do it.
Code: Select all
on mouseUp
if vTS is not 0
then
answer "Trauma Supplies missing from inventory. Please go back and complete Trauma section"
else
if vWhite is not 0
then
answer "ALS supplies missing from inventory. Please go back and complete ALS section"
else
if vMisc is not 0
then
answer "Miscellaneous Supplies missing from inventory. Please go back and complete Miscellaneous section"
else
if vAirway is not 0
then answer "Airway supplies missing from inventory. Please go back and complete Airway section"
else
put "Currently Stocked Items" & cr & fld "iot" card "Send" & cr & cr & "Items Needing Re-stocked" & cr & fld "not" card "Send" into vBody
mobileComposeMail "Test E-mail", someEmail@verizon.net,,, vBody, tAttachment
end if
end if
end if
end if
end mouseUp
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Thu Feb 14, 2013 4:36 am
I go way back, and in HC one had to do it that way.
This cries out for a switch construction. So much more compact and readable.
switch
case vts is not 0
answer ...
break
case vWhite is not 0
answer something else
break
etc.
end switch
Craig Newman
-
jsburnett
- VIP Livecode Opensource Backer

- Posts: 121
- Joined: Fri Mar 09, 2007 9:47 pm
Post
by jsburnett » Thu Feb 14, 2013 9:46 pm
Hi,
Why not try 'or'
(It may make for a long if statement, which can be decreased in size in the future)...
but
if a is not true or b is not true or c is not true or d is not true
then
do 1 of the above is not true
else
do all are true
end if
Also, I may be missing the point here...
John
-
KennyR
- Posts: 256
- Joined: Thu Jan 19, 2012 4:25 am
Post
by KennyR » Fri Feb 15, 2013 3:21 pm
Thanks guys for the input....I had tried to write this as a switch in a number of different ways but was getting some unusual results....I tried to break each statement, but it seemed as if it was still pushing down the cases and firing the default statement. I even tried doing the "or" and making a long statement of each but was still having issues....the "exit mouseUp" trick in the end did it for me......I feel I have gotten good at writing "if/else" and "switch" functions so I was unsure what had actually happend that I wasn't getting the results I wanted....Most of the time when I write programs like the one I'm currently doing, I can't help but ask myself if there is a simpler more elegant way to structure my code. I REALLY wish there was someone down the street from me that worked in LC and could mentor me!!! Alas, I will keep pecking on the keyboard and reading until that day comes!!!
-
Newbie4
- VIP Livecode Opensource Backer

- Posts: 332
- Joined: Sun Apr 15, 2012 1:17 am
-
Contact:
Post
by Newbie4 » Sat Feb 16, 2013 3:57 am
This may not be more elegant but it is simpler and easier to understand. It also checks all of them each mouseUp.
Code: Select all
Global vTSZero, vWhiteZero, …
on openCard
put false into vTSZero
put false into vWhiteZero
…
end openCard
on mouseUp
if vTS is 0 then
put true into vTSZero
else
answer "Trauma Supplies missing from inventory. Please go back and complete Trauma section"
end if
if vWhite is 0 then
put true into vWhiteZero
else
answer "ALS supplies missing from inventory. Please go back and complete ALS section"
end if
…
if vTSZero and vWhiteZero and … then
put "Currently Stocked Items" & cr & fld "iot" card "Send" & cr & cr & "Items Needing Re-stocked" & cr & fld "not" card "Send" into vBody
mobileComposeMail "Test E-mail", someEmail@verizon.net,,, vBody, tAttachment
end if
end mouseUp
This may not be the best way to do it (globals are discouraged in LiveCode) but I am new to LiveCode and this is the way I would have done it elsewhere.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Sat Feb 16, 2013 4:30 am
Hi Kenny,
I'm chiming in because the switch thing bothers me:
Code: Select all
local vTS,vWhite,vMisc
on mouseUp
put 0 into vTS
put 0 into vWhite
put 0 into vMisc
switchIt
end mouseUp
on switchIt
switch
case vTS <> 0
answer "vTS <> 0"
break
case vWhite <> 0
answer "vWhite <> 0"
break
case vMisc <> 0
answer "vMisc <> 0"
break
default
answer "Currently Stocked Items..."
end switch
end switchIt
This works for me.
I use if-then far too often when I should be using switch. Can you tell me what are your results?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
magice
- Posts: 457
- Joined: Wed Mar 18, 2009 12:57 am
Post
by magice » Sat Feb 16, 2013 6:25 am
I just love seeing the many different ways people code the same scenario. This has to be the most educational board I have ever been on.
-
KennyR
- Posts: 256
- Joined: Thu Jan 19, 2012 4:25 am
Post
by KennyR » Tue Feb 19, 2013 12:46 pm
Simon, as promised, here is what I went with in the end. I like this because it "breaks" at each condition, and doesn't run through them all and alert each section that needs completed until it passes the previous condition. I prefer to use a switch in these cases, but after trying multiple ways of doing it, this seemed to work best. Plus, as soon as I find something that works, I move on!

No need to fix what ain't broke...Thanks everyone for all your great input...that is what I LOVE about this community....everyone likes to help each other out...in the end, we all learn a few new tricks!
Code: Select all
global vEmail,vShift,vCrew,vRig
on touchEnd pld
mobGUIUntouch the long id of me
if vTS is not 0
then
answer "Trauma Supplies missing from inventory. Please go back and complete Trauma section"
exit touchEnd
end if
if vWhite is not 0
then
answer "ALS supplies missing from inventory. Please go back and complete ALS section"
exit touchEnd
end if
if vMisc is not 0
then
answer "Miscellaneous Supplies missing from inventory. Please go back and complete Miscellaneous section"
exit touchEnd
end if
if vAirway is not 0
then
answer "Airway supplies missing from inventory. Please go back and complete Airway section"
exit touchEnd
end if
put fld "defaultMail" group "emailAlert" into vEmail
put vCrew & cr & cr &"Currently Stocked Items" & cr & fld "iot" card "Send" & cr & cr & "Items Needing Re-stocked" & cr & fld "not" card "Send" into vBody
mobileComposeMail vRig && vShift, vEmail,,, vBody, tAttachment