ask box cancelled-how to stop further actions

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
saratogacoach
Posts: 87
Joined: Thu Jul 17, 2008 8:42 pm

ask box cancelled-how to stop further actions

Post by saratogacoach » Thu Jun 25, 2009 5:09 pm

Hi,

In a stack, I've set up a menu button which asks the user to enter their name and email address before showing an email button.

So, I am using an ask box, putting "it" into a variable. An ask box seems to have 3 options: (1) the user enters something, (2) they enter nothing and click OK, or (3) they cancel.

What I would like to set up: if the user enters nothing or cancels, the email button remains invisible, does not show.

So, I use "if it is not empty, then show the email button...end if"
And, 'if it is empty then answer "Please enter..." end if'

Should work, but doesn't.

I have also tried if <variable that it is put into> is empty then "Please enter..." end if, etc.

When clicking OK with nothing entered or clicking cancel, the email button still shows.

Any way to prevent the email button from showing if the requested information is not entered (just blank) or the ask box is canceled?

Here's the code I'm using now that doesn't succeed:

Code: Select all

ask "Please enter your name and email address"
        put it into xName 
        answer xName
        if it is not empty then
           show button "Send email"
           end if
           if it is empty then
              answer "Please enter your name and email address" titled "Please Provide Information"
              end if
By the way, after some further experimenting: if I remove the "answer" lines, everything works OK. So, if I cannot get it to work with the "answer" actions, then maybe the best approach will be to leave them out.

Kind Regards,
saratogacoach
LiveCode 4.6.0, Windows 7 Home Premium 64 bit, Core i7 2.80, 8G RAM, ATI Radeon HD5770

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Jun 25, 2009 6:54 pm

Hi saratogacoach,

the it variable got you here. With the answer dialog you fill the it variable anew, but you expected it to contain the it from the answer dialog.
You did put 'it' into a variable and that is what you should have tested for.
Whenever you use it, like in get commands, answer or ask command it is good practice to put the content of it immediately into a variable. Because one tends to forget what else could fill the it variable. So not surprisingly when you left out the answer command it worked. Here is your original version with a slight variation that works for me:

Code: Select all

on mouseUp
   ask "Please enter your name and email address"
   put it into xName
   put the result into tResult -- if the user canceled the result contains "cancel"
   --breakpoint
   answer xName   -- with the answer xxx you fill your it variable anew
   if xName is not empty then 
      show button "Send email"
   end if
   if (xName is empty) and (not tResult is empty) then
      answer "Please enter your name and email address" titled "Please Provide Information"
   end if
end mouseUp
if the user cancels the ask command it is empty but the result contains 'cancel'. So I changed the script to only show the last answer command if the user did not cancel the ask command (implying that the user forgot to fill in the name and email by just hitting return)

regards

Bernd

saratogacoach
Posts: 87
Joined: Thu Jul 17, 2008 8:42 pm

Post by saratogacoach » Thu Jun 25, 2009 9:45 pm

Thanks, Bernd

That was very helpful and instructive.

I made one change, which equally worked:

instead of

Code: Select all

if (xName is empty) and (not tResult is empty) then 
I used

Code: Select all

if (xName is empty) or (not tResult is empty) then
.

This way, if the user fails to enter the information by leaving it blank or by canceling, they are shown a reminder message.

Again, much thanks.
saratogacoach
LiveCode 4.6.0, Windows 7 Home Premium 64 bit, Core i7 2.80, 8G RAM, ATI Radeon HD5770

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Jun 25, 2009 10:07 pm

Hi SaratogaCoach,
This way, if the user fails to enter the information by leaving it blank or by canceling, they are shown a reminder message.
if you want to remind the user regardless whether the user cancelled or left it blank then you could just say:

Code: Select all

if xName is empty then
because than the result is pointless. xName will be empty when the user cancelled the ask dialog. The result only gives you the additional information why the ask command did not return anything: because of not filling anything in or because of cancel.

regards
Bernd

saratogacoach
Posts: 87
Joined: Thu Jul 17, 2008 8:42 pm

Post by saratogacoach » Thu Jun 25, 2009 11:23 pm

Hi Bernd,

Yes, close to what I initially tried. I used "it" instead of the variable xTemp, which doesn't work.

'a difference which makes a difference.' :)

Kind Regards,
saratogacoach
LiveCode 4.6.0, Windows 7 Home Premium 64 bit, Core i7 2.80, 8G RAM, ATI Radeon HD5770

Post Reply