script problem; button returned

I am making a new script.

The structure of the script has to be:
question 1 > yes or no
if question 1 = yes do something
if question 1 = no go tot question 2

question 2 > 1 or 2
if question 2 = 1 go to question 3
if question 2 = 2 go to question 4

question 3 > a, b or c
if question 3 = a do something
if question 3 = b do something
if question 3 = c do something

question 4 > d, e or F
if question 3 = d do something
if question 3 = e do something
if question 3 = f do something

Now my problem is I can’t let work the second question…

set TempKArray to {“20”, “24”}
set TempAArray to {“90”, “75”, “70”, “55”, “35”}
set TempRArray to {“70”, “65”, “55”, “45”, “30”}
set Prijzensql to “SELECT tbProducts.prod_id, tbProducts.prod_code AS Prod_code, tbProductProperties.prop_description AS Description,
tbProductProperties.prop_prize_standard_pc AS S, tbProductProperties.prop_prize_others_pc AS A,
tbProductProperties.prop_width AS Breedte, tbProductProperties.prop_height AS Hoogte,
tbProductProperties.prop_length AS Lengte, tbProductProperties.prop_weight AS Gewicht, tbProductProperties.prop_type AS Type,
tbProductProperties.prop_height AS W, tbProductProperties.prop_length AS X, tbProductProperties.prop_type AS Y,
tbProductProperties.prop_width AS Z, tbProductProperties.prop_fk_lang_id AS Lang_id
FROM tbProducts INNER JOIN
tbProductProperties ON tbProducts.prod_id = tbProductProperties.prop_fk_prod_id”

set OriginalSql to (display dialog "Moet je enkel nieuwe prijzen inhalen?" buttons {"Ja", "Nee"} default button {"Ja"})
if button returned of OriginalSql is "Ja" then
	
	set OriginalSql to Prijzensql
else
	set OriginalSql to (display dialog "Hoeveel kamertemperaturen wens je weer te geven?" buttons {"1", "2"} default button {"1"})
	if button returned of OriginalSql is "1" then
		set Kamer1 to (choose from list TempKArray with prompt "Selecteer de gewenste kamertemperatuur." default items {"20"} without multiple selections allowed) as text
		set OriginalSql to (display dialog "Hoeveel afgiftes wens je weer te geven?" buttons {"2", "3"} default button {"2"})
		if button returned of OriginalSql is "2" then
			set Em to {}
			repeat with i from 1 to count of TempAArray
				set end of Em to (item i of TempAArray & "/" & item i of TempRArray) as string
			end repeat
			set Antw1 to (choose from list Em with prompt "Selecteer de gewenste eerste afgifte" default items {"75/65"} without multiple selections allowed) as text
			set Aanvoer1 to characters 1 thru 2 of Antw1 as string
			set Retour1 to characters 4 thru 5 of Antw1 as string
			set Em2 to {}
			repeat with x from 1 to count of items of Em
				set n to item x of Em
				if n is not in Antw1 then set end of Em2 to n
			end repeat
			set Antw2 to (choose from list Em2 with prompt "Selecteer de gewenste tweede afgifte" default items {"55/45"} without multiple selections allowed) as text
			set Aanvoer2 to characters 1 thru 2 of Antw2 as string
			set Retour2 to characters 4 thru 5 of Antw2 as string
			set OriginalSql to KAAsql
		end if
	end if
end if

end tell

who can help me???

Hi,

the structure of your script should look like


set {button returned:buttonReturned} to (display dialog "question 1" buttons {"Yes", "No"} default button "Yes")
if buttonReturned is "Yes" then
	-- do something  (question 1 answer Yes)
else
	set {button returned:buttonReturned} to (display dialog "question 2" buttons {"1", "2"} default button "1")
	if buttonReturned is "1" then
		set {button returned:buttonReturned} to (display dialog "question 3" buttons {"a", "b", "c"} default button "c")
		if buttonReturned is "a" then
			-- do something (question 3 answer a)
		else if buttonReturned is "b" then
			-- do something (question 3 answer b)
		else
			-- do something (question 3 answer c)
		end if
	else
		set {button returned:buttonReturned} to (display dialog "question 4" buttons {"d", "e", "f"} default button "f")
		if buttonReturned is "d" then
			-- do something (question 4 answer d)
		else if buttonReturned is "e" then
			-- do something (question 4 answer e)
		else
			-- do something (question 4 answer f)
		end if
	end if
end if

some notes:
¢ without multiple selections allowed is the default setting of choose from list. You can omit it.

¢ The default button parameter of display dialog doesn’t have to be a list

¢ If the user presses “Cancel” choose from list returns boolean false, therefore it’s recommended to check for it, e.g.


set Antw1 to (choose from list Em with prompt "Selecteer de gewenste eerste afgifte" default items {"75/65"}) as text
if Antw1 is "false" then return

¢ An easier way to get a substring is


set Aanvoer2 to text 1 thru 2 of Antw2

Thank you very much… I will try it and let you know if it worked or not…

it works!!

Now I want to include the “false” function (see above).

set languageId to choose from list CountryArray with prompt "Selecteer de catalogus prijzen die na het linken moeten worden geladen." default items {"01.België"} OK button name "Update document"
		if languageId is "false" then return

Clicking the button “cancel” doesn’t stop the action.

How do I have to resolve this problem?

In your first script you’re coercing the result (a list of the chosen element(s) or boolean false) to text.
In this case you have to compare the result with a string


set c to choose from list {"A", "B"} as text
if c is "false" then return

Using the normal syntax the result must be compared with a boolean value


set c to choose from list {"A", "B"}
if c is false then return

Consider, that the result of the second syntax is always a list, if the user has chosen an item

The action won’t stop when i include

set c to choose from list {"A", "B"} as text
if c is "false" then return

The next question appears :frowning:

sorry, my fault, the correct syntax is


set c to (choose from list {"A", "B"}) as text
if c is "false" then return