Quiting Classic Applet

Hello All,
This is my last step to complete my script.
I am having trouble assigning a Quit command to a Dialog Director button. The Applet wiil quit, but I get a message that the variable Language was undefined.
Is there a way to quit in a clean way?
Please see my code below.
Thank you in advance,
Damon

set Language to DoMenu(["English", "French", "German", "Spanish"])
on DoMenu(theLanguage)
	set [_next, _cancel, _choice] to dd auto dialog {size:[390, 240], contents:[¬
		{class:push button, bounds:[320, 210, 380, 230], name:"Next"}, ¬
		{class:push button, bounds:[240, 210, 300, 230], name:"Cancel"}, ¬
		{class:radio group, bounds:[10, 45, 130, 61], button offset:[120, 50], max down:3, contents:theLanguage}, ¬
		{class:static text, bounds:[10, 10, 250, 26], contents:"Choose an Language:"} ¬
], timeout after:200000} with grayscale
	if _next then
		return theLanguage's item _choice
	else if _cancel then
		quit
		if Language is "English" then
			set lang to "En"
		else if Language is "French" then
			set lang to "FR"
		else if Language is "Italian" then
			set lang to "IT"
		else if Language is "German" then
			set lang to "GR"
		else if Language is "Spanish" then
			set lang to "SP"
		else if Language is "Japanese" then
			set lang to "JP"
		end if
	end if
end DoMenu

Nomad - If you have recently died then please do not bother to reply. Otherwise a response would be appreciated. Is everything working OK now or do you stil have a problem?
Andreas

Sorry Andreas,
I am not dead, I just got busy at work. I appreciate all of your help.
I am still having the problem. The sample script I posted was only the first section of the script. If I use your fix on just that section I works fine, but the next subroutine continues and I get the above mentioned error. I am a beginner at apple script as you can tell and not an expert on subroutines. If you could take a look at my entire script below and give any suggestions I would appreciate it. I would like the cancel button end the script with no error messages on any window in the script regardless if all of the variable have been defined or not.
Thank you,
Damon

set Language to DoMenu(["English", "French", "German", "Spanish"]) -- "Italian", "Japanese" to be added
on DoMenu(theLanguage)
	set [_next, _cancel, _choice] to dd auto dialog {size:[390, 240], contents:[¬
		{class:push button, bounds:[320, 210, 380, 230], name:"Next"}, ¬
		{class:push button, bounds:[240, 210, 300, 230], name:"Cancel"}, ¬
		{class:radio group, bounds:[10, 45, 130, 61], button offset:[120, 50], max down:3, contents:theLanguage}, ¬
		{class:static text, bounds:[10, 10, 250, 26], contents:"Choose an Language:"} ¬
		], timeout after:200000} with grayscale
	if _next then
		return theLanguage's item _choice
	else if _cancel then
		tell me to quit
	end if
	if Language is "English" then
		set lang to "En"
	else if Language is "French" then
		set lang to "FR"
	else if Language is "Italian" then
		set lang to "IT"
	else if Language is "German" then
		set lang to "GR"
	else if Language is "Spanish" then
		set lang to "SP"
	else if Language is "Japanese" then
		set lang to "JP"
	end if
end DoMenu
if Language is "English" then
	set OSchoice to (["9.1"])
else if Language is "French" then
	set OSchoice to (["9.1", "9.2", "10.1"])
else if Language is "Italian" then
	set OSchoice to (["9.1", "9.2"])
else if Language is "German" then
	set OSchoice to (["10.1"])
else if Language is "Spanish" then
	set OSchoice to (["9.1"])
else if Language is "Japanese" then
	set OSchoice to (["9.1"])
end if
set OS to DoMenu2(OSchoice)
on DoMenu2(theOS)
	set [_next, _cancel, _choice] to dd auto dialog {size:[390, 240], contents:[¬
		{class:push button, bounds:[320, 210, 380, 230], name:"Next"}, ¬
		{class:push button, bounds:[240, 210, 300, 230], name:"Cancel"}, ¬
		{class:radio group, bounds:[10, 45, 130, 61], button offset:[120, 50], max down:2, contents:theOS}, ¬
		{class:static text, bounds:[10, 10, 250, 26], contents:"Choose an OS version:"} ¬
		], timeout after:200000} with grayscale
	if _next then
		return theOS's item _choice
	else if _cancel then
		tell me to quit
	end if
end DoMenu2
set apps to DoMenu3(["With Applications", "Without Applications"])
if apps is "With Applications" then
	set wapps to "WA"
else if apps is "Without Applications" then
	set wapps to "NA"
end if
on DoMenu3(theApps)
	set [_next, _cancel, _choice] to dd auto dialog {size:[390, 240], contents:[¬
		{class:push button, bounds:[320, 210, 380, 230], name:"Next"}, ¬
		{class:push button, bounds:[240, 210, 300, 230], name:"Cancel"}, ¬
		{class:radio group, bounds:[50, 80, 300, 95], button offset:[120, 50], max down:2, contents:theApps}, ¬
		{class:static text, bounds:[10, 10, 250, 26], contents:"Choose With or Without Applications:"} ¬
		], timeout after:200000} with grayscale
	if _next then
		return theApps's item _choice
	else if _cancel then
		tell me to quit
	end if
end DoMenu3
set excludeDisks to {"Mac Images v1.1", "Mac_OS_Scripts", "Mac_OS_Images"}
tell application "Finder" to set dlist to (name of every disk whose name is not in excludeDisks) as list
set diskq to DoMenu4(dlist)
on DoMenu4(thediskq)
	set [_next, _cancel, _choice] to dd auto dialog {size:[390, 240], contents:[¬
		{class:push button, bounds:[320, 210, 380, 230], name:"Next"}, ¬
		{class:push button, bounds:[240, 210, 300, 230], name:"Cancel"}, ¬
		{class:radio group, bounds:[10, 45, 130, 61], button offset:[120, 50], max down:3, contents:thediskq}, ¬
		{class:static text, bounds:[10, 10, 250, 26], contents:"Choose a Volume:"} ¬
		], timeout after:200000} with grayscale
	if _next then
		return thediskq's item _choice
	else if _cancel then
		tell me to quit
	end if
end DoMenu4
set imagestring to "MAC_OS_IMAGES:MacOS9.1:" & lang & OS & wapps & ".img"
set tWhatToRestore to imagestring
set tWhereToRestore to "" & diskq & ":"
launch application "Apple Software Restore"
tell application "Apple Software Restore" 
	with timeout of 1000000 seconds
		try
			Restore tWhatToRestore to ¬
			tWhereToRestore placing in entire volume ¬
			preprocess erasing disk ¬
			copying everything ¬
			warning true ¬
			barber pole speed 10 without checksum, removing unwanted files and erasing on failure
		on error tErrorMessage number tErrorNumber
			display dialog ("Error: " & "[" & tErrorMessage & "]" & ", [" & tErrorNumber & "]")
		end try
	end timeout
	quit
end tell
tell application "Finder"
	set startupDisk to name of startup disk
	set theDisks to every disk whose (name is not startupDisk and ejectable is true)
	repeat with x in theDisks
		set diskName to name of x
		try
			put away disk diskName
		end try
	end repeat
end tell
if imagestring is "MAC_OS_IMAGES:MacOS9.1:En9.1WA.img" then
	set Imagechoice to "English 9.1"
--else if imagestring is "Fr9.1WA.img" then
	--set Imagechoice to (["French 9.1"])
--else if imagestring is "It9.1WA.img" then
	--set Imagechoice to (["Italian 9.1"])
--else if imagestring is "Gr9.1WA.img" then
	--set Imagechoice to (["german 9.1"])
--else if imagestring is "Sp9.1WA.img" then
	--set Imagechoice to (["Spanish 9.1"])
--else if imagestring is "Jp9.1WA.img" then
	--set Imagechoice to (["Japanese 9.1"]) 
end if
tell application "Finder"
	activate
	select disk Imagechoice
	open selection
	close container window of disk Imagechoice 
end tell
set timagechoice to "" & Imagechoice & ":"
tell application "Startup Disk"
	activate
	set startup disk alias to alias timagechoice
	quit
end tell
tell application "Finder"
	restart
end tell

: Nomad - If you have recently died then please do not bother to
: reply. Otherwise a response would be appreciated. Is
: everything working OK now or do you stil have a problem?
: Andreas
I will be gone for the next four days, so don’t worry. I will still be alive and kicking
Damon

I sympathise with Nomad, as I have the same problem. It’s been tearing my hair out all morning.
Try this code::

set dBox to display dialog ¬
  "What are we working on?" with icon caution ¬
  buttons {"Plan A", "Plan B", "None"} ¬
  giving up after 30
if gave up of dBox is true then 
  quit me 
set dButton to button returned of dBox 
if dButton is "Plan A" then
  set d to "A" 
else if dButton is "Plan B" then
  set d to "B" 
else
  quit me 
end if

If I let the DB time out, or if I hit “none”, the rest of the script keeps trundling along as if nothing happened. This is NOT what I want.
If the quit command doesn’t quit, then why in the hell is it there?
Or what are we missing? ---- Obbie

Just remove the last ‘else’…

else if dButton is “Plan B” then
set d to “B”
end if

The script will then quit simply because it has nothing else to do!
If you ever ask a script to quit you need to consider giving it a ‘quit handler’, with at the very least the command “continue quit”.
Sorry if it sounds critical but you should do a lot of reading/studying/thinking before you decide that the blame must lie with that stupid AppleScript language or the moronic computer…
Andreas
PS Sorry, but that previous posting’s code is simply far, far, far too long for me to begin to contemplate trying to deal with - and I suspect that I also speak for others. I suggest you do things which are simpler/shorter, get them running perfectly (with help here if needed) and only then tackle bigger projects. You have a good example here - that last posting was short, easy to deal with, and - hopefully - has enabled its author to learn something. Sorry!

PS: I was just clearing out my clipboards and spotted that you had a quit command higher up to deal with the thing timing out. You probably realise from what I wrote earlier that all you need to do is delete that line. The script doesn’t need to be told what to do when time is up - it already knows! All you are doing is worrying it into trying to work out what on earth you want it to do before it says goodbye. To find out it searches for your ‘quit handler’, can’t find it and protests.
Andreas

: Just remove the last ‘else’…
: else if dButton is “Plan B” then
: set d to “B”
: end if
: The script will then quit simply because it has
: nothing else to do!

In the interests of simplicity, I only submitted the snippet I’ve been experimenting with. A lot of other things happen beyond this piece of code, so just allowing it to “run out” is not an option.

The snippet, as I’ve submitted it, sets a variable one way or another. That variable is used later in the program, and if the user signals the intention to bail out (by hitting the ‘none’ button or giving up), the script chokes later on when it finds that variable undefined.

I don’t want the program to flow off the bottom of this piece of code, I want it to quit, just like the command says it’s supposed to work.

: If you ever ask a script to quit you need to consider giving it a
: ‘quit handler’, with at the very least the command
: “continue quit”.

I tried that, same result.
The script keeps marching along as if nothing happened.

: Sorry if it sounds critical but you should do a lot of
: reading/studying/thinking before you decide that the blame
: must lie with that stupid AppleScript language or the moronic
: computer…

With all due respect, what the hell do you think I’ve been doing? I’ve worked with AppleScript on-and-off for years, and I’ve had the ‘quit’ command work in other scripts (although usually directed at a scriptable application, not the script itself. But I have had ‘quit me’ work before in the way I’m trying to make it work now.

: PS Sorry, but that previous posting’s code is simply far, far,
: far too long for me to begin to contemplate trying to deal
: with - and I suspect that I also speak for others. I suggest
: you do things which are simpler/shorter, get them running
: perfectly (with help here if needed) and only then tackle
: bigger projects. You have a good example here - that last
: posting was short, easy to deal with, and - hopefully - has
: enabled its author to learn something. Sorry!

You praise me for submitting a minimalist snippet that isolates the problem being discussed, then you assume that the end of this piece of code is the end of the larger program.

Once again: ‘quit me’ should mean ‘quit me’, NOT ‘NOP’ or ‘do nothing’ or ‘continue on to the next statement, if any.’

Any other ideas?

Obbie