"Go To" equivalent?

Without line numbers and “go to” statements, how do you skip large sections of the code?

Lets say I have 3 buttons and 3 actions. One button executes the first part of a script, the second button executes the second part, and the third executes the ENTIRE script. How could you pull this off?

Try something like this:

display dialog buttons {"Do One", "Do Two", "Do All"}
get button returned of result

if result is "Do One" then
	yourFirstPart()
else if result is "Do Two" then
	yourSecondPart()
else
	yourFirstPart()
	yourSecondPart()
end if

on yourFirstPart()
	--whatever 1
end yourFirstPart

on yourSecondPart()
	--whatever 2
end yourSecondPart

display dialog buttons {"Do One", "Do Two", "Do All"}
set theButton to button returned of result

if theButton is "Do One" or theButton is "Do All" then
	--whatever 1
end if

if theButton is "Do Two" or theButton is "Do All" then
	--whatever 2
end if

Use handlers. Something like this:

set Proc to button returned of (display dialog "Which Process do you want?" buttons {"Process #1", "Process #2", "Processes 1/2/3"})

set msg to ""

if Proc = "Process #1" then
	Part_1()
	display dialog msg
	return
else if Proc = "Process #2" then
	Part_2()
	display dialog msg
	return
else if Proc = "Processes 1/2/3" then
	Part_1()
	Part_2()
	Part_3()
	display dialog msg
end if

to Part_1()
	set my msg to "Part_1 done"
end Part_1

to Part_2()
	set my msg to my msg & return & "Part_2 done"
end Part_2

to Part_3()
	set my msg to my msg & return & "Part_3 done"
end Part_3

EDIT – Oops, Bruce beat me to it

I have a similar question but I would want to add it to the end of the script.
Like if you want to do the second part agian can you have the script start from the point you choose? Skipping the begining of the script where you already answered a common question.

Thanks

Would something like this work for you?

on run
	display dialog buttons {"Do One", "Do Two", "Do All"}
	get button returned of result
	
	if result is "Do One" then
		yourFirstPart()
	else if result is "Do Two" then
		yourSecondPart()
	else
		yourFirstPart()
		yourSecondPart()
	end if
	
	display dialog buttons {"Do Two Again", "Done"}
	
	if button returned of result is "Do Two Again" then yourSecondPart()
end run

on yourFirstPart()
	--whatever 1
end yourFirstPart

on yourSecondPart()
	--whatever 2
end yourSecondPart

Thanks guys! I haven’t done any serious programming since my Apple IIe and Atari 400/800 days, so it’s going to take me a while to adjust to doing things without line numbers, “for/next” loops and “go to” statements.

And I’m not sure if I entirely understand handlers, but I’ll play with them until I figure them out. Heh, kind of like women in the regard! :wink:

You might look here for a good start on handlers: “Getting Started with Handlers (Part 1)” by Ben Waldie

Look at “repeat” control structures. You have a number of options available:

repeat x from 1 to 10
… code here…
end repeat


repeat while x < 100
… code here …
end repeat


repeat with x in myList
… code here
end repeat


These are just a few examples. Also, if you have ever used sub-routines then you’ll find handlers are similar in concept.

Good luck,
Brad Bumgarner, CTA

Bruce thanks for the example on handlers. I think I understand how they work, but it seems you can not bring an answer from one part to another. Lets say I answered a question in yourfirstpart() and I needed that answer to carry through to yoursecondpart() and yourthirdpart(). Is this possilbe I’m been trying to work it out but with no luck.

Thanks

Something like this?

property FirstAns : missing value
property SecAns : missing value

display dialog buttons {"Do One", "Do Two", "Do All"}
get button returned of result

if result is "Do One" then
	yourFirstPart()
else if result is "Do Two" then
	yourSecondPart()
else
	yourFirstPart()
	yourSecondPart()
end if

display dialog buttons {"Do Two Again", "Done"}

if button returned of result is "Do Two Again" then yourSecondPart()

on yourFirstPart()
	--whatever 1
	--set my FirstAns to a variable here
end yourFirstPart

on yourSecondPart()
	--whatever 2
	--set my SecAns to something from here
end yourSecondPart

Adam Thanks alot that worked perfectly. I’m learning more each day with the help of everyone in the forums. Now if I can just get my pesky spot color problem solved I’ll be in business.

Thanks again