I want to say thanks for all of those who has been helping me, my script is really progressing.
Depending on the value entered by the user the repeat loop may or may not work.
For example :
Starting : 1 and Ending: 1 - worked
Starting : 7 and Ending: 8 - worked
Starting : 8 and Ending: 10 - DOES NOT work
Starting : 10 and Ending: 12 - worked
Starting : 9 and Ending: 9 - worked
Starting : 9 and Ending: 12 - DOES NOT work
Starting : 10 and Ending: 10 - worked
Starting : 6 and Ending: 12 - DOES NOT work
As soon the number 10 is within the combination it does not work. Bizarre!
Does anyone has an idea or experimented this problem before. Does it have to do with the way I getting the information from the user in using the “Display Dialog”
Thanks in advance!
set newBatchNumber to 1
set startingNumber to the text returned of (display dialog "Please enter STARTING number" buttons {"OK", "?"} default button 2 default answer newBatchNumber)
set endingNumber to the text returned of (display dialog "Please enter ENDING number" buttons {"OK", "?"} default button 2 default answer startingNumber)
set theEventNumber to startingNumber
display dialog "beforetRepeat theEventNumber: " & theEventNumber & " endingNumber: " & endingNumber
repeat until theEventNumber is greater than endingNumber
display dialog "Repeat theEventNumber: " & theEventNumber & " endingNumber: " & endingNumber
set theEventNumber to (theEventNumber + 1)
end repeat
I got it to work in doing the following in adding a function as previously suggested by StefanK.
However, is there a better way to capture the information from the user. For example in having the user entering both the Starting and the Ending number in the same Dialog Box.
Regards!
Daniel
set newBatchNumber to 1
set startingNumber to the text returned of (display dialog "Please enter STARTING number" buttons {"OK", "?"} default button 2 default answer newBatchNumber)
set endingNumber to the text returned of (display dialog "Please enter ENDING number" buttons {"OK", "?"} default button 2 default answer startingNumber)
set theEventNumber to startingNumber
display dialog "beforetRepeat theEventNumber: " & theEventNumber & " endingNumber: " & endingNumber
repeat until my twoDigitStr(theEventNumber) is greater than my twoDigitStr(endingNumber)
display dialog "Repeat theEventNumber: " & theEventNumber & " endingNumber: " & endingNumber
set theEventNumber to (theEventNumber + 1)
end repeat
on twoDigitStr(theNumber)
--display dialog "T: " & theNumber
return text -2 thru -1 of ("00" & theNumber)
end twoDigitStr
I showed someone recently how to get 2 numbers from 1 dialog. Look at my post #2 here. You want the repeat loop at the top of the script. It has checking to make sure both numbers entered are actually numbers and that the second number is larger than the first.
The original script failed because ‘display dialog’ returns text, not an actual number. “8” is lexically greater than “10” (which begins with “1”), so the repeat loop isn’t executed with those values.
Your fix of turning each value into a two-digit text every time works, but is the least efficient way of doing things. It would be better to convert the input values to integers straight away and then do everything in the number realm rather than constantly switch between numbers and text.
It would also be neater to use ‘repeat with . from . to .’ for the repeat.
set newBatchNumber to 1
set startingNumber to (the text returned of (display dialog "Please enter STARTING number" buttons {"OK", "?"} default button 2 default answer newBatchNumber)) as integer -- NB. 'as integer'.
set endingNumber to the (text returned of (display dialog "Please enter ENDING number" buttons {"OK", "?"} default button 2 default answer startingNumber)) as integer -- Ditto.
display dialog "beforetRepeat theEventNumber: " & startingNumber & " endingNumber: " & endingNumber
repeat with theEventNumber from startingNumber to endingNumber
display dialog "Repeat theEventNumber: " & theEventNumber & " endingNumber: " & endingNumber
end repeat