Exit Repeat and Quit

Hi Folks,

Can someone please help me solving this issue?

if Q does not contain "T-Mobile D" then
	repeat
		if Q contains "T-Mobile A" then
			set Q to "T-Mobile D"
			exit repeat
		end if
		
		try
			tell current application
				set requested_status to display dialog "Do you want to connect with" & Q & "?" buttons {"Cancel", "Yes"} default button "Cancel"
				
				if button returned of requested_status is "Yes" then
					exit repeat
				else if button returned of requested_status is "Cancel" then
					quit theApplication
				end if
			end tell
		end try
	end repeat
end if

Can someone tell me please how I can close theApplication when the “Cancel” button is pressed? At the moment only the “Yes” button is working, because then the repeat loop will be exited!

Thanks for any help!

Best Regards,

Stefan

Pressing “Cancel” in `display dialog will cause an error (number -128, “User canceled.”).

Try something like this:

if Q does not contain "T-Mobile D" then
	repeat
		if Q contains "T-Mobile A" then
			set Q to "T-Mobile D"
			exit repeat
		end if
		
		try
			tell current application
				try
					display dialog "Do you want to connect with" & Q & "?" buttons {"Cancel", "Yes"} default button "Cancel"
					exit repeat
				on error
					quit theApplication
					error number -128 -- cancel
				end try
			end tell
		end try
	end repeat
end if

Hi Bruce,

thanks for your feedback! It is working fine, but I have to press “Cancel” 3 times until it quits…

Best Regards,

Stefan

I didn’t see your other try block there. Try this instead:

if Q does not contain "T-Mobile D" then
	repeat
		if Q contains "T-Mobile A" then
			set Q to "T-Mobile D"
			exit repeat
		end if
		
		try
			tell current application
				display dialog "Do you want to connect with" & Q & "?" buttons {"Cancel", "Yes"} default button "Cancel"
				exit repeat -- user chose "yes"
			end tell
		on error errMsg number errNum
			if errNum is -128 then
				quit theApplication
				error number -128 -- cancel
			end if
		end try
	end repeat
end if

Hi Bruce,

perfect! You are great! Works like a charm…

Thanks a lot,

Stefan