Stop the FMP Cycle

I have a script that repeats the records in FMP. This script pulls data from a field pastes as a name of a folder then moves to the next record and does the same. The problem I am having is that it continues even after the last record and tries to paste the data as the folder name only to cause an error since that name is taken. How can I stop this cycle?
Thank you ahead of time for any thoughts.

: it continues even after the last record
I can’t see anyone being able to answer you without sight of at least the code you have used for the repeat loop.
Andreas

Unless you have made alterations to your script for this posting then it makes no sense to me. Having set formnum and formnum2 to exactly the same value it does not make sense to ask if they equal each other, does it?
Do you actually mean cell “form num”, i.e. a cell named “form num” or did you intend cell formNum, the cell whose number is (the number in the variable formNum)?
Andreas

Here’s the whole thing:

global myvendor
global myversion
global formnum
global formnum2
global the_number_of_records
--Finder will make a folder with the Vendor name on it.
tell application "Finder"
	activate
	select disk "Apps"
	open selection
	make new folder at disk "Apps"
	select folder "untitled folder" of disk "Apps" with timeout of 20 seconds
	tell application "FileMaker Pro"
		set the_number_of_records to the count of records of document 1
		show every record in database "Test Gang"
		sort database "Test Gang" by field "Form Num" in order ascending
		set myvendor to cell "Print Vendor" of record 1 of database "test Gang"
		tell application "Finder"
			select folder "untitled folder" in disk "Apps"
			set name of selection to myvendor
		end tell
		repeat while myvendor = cell "Print Vendor"
			if myvendor is not true then -- added 2/22/02
				display dialog "File Missing" buttons {"Find File", "Cancel"} default button "Find File" -- added 2/22/02
			else
				tell application "Finder"
					select folder myvendor in disk "Apps"
					make new folder in folder myvendor of disk "Apps"
				end tell
				tell application "FileMaker Pro"
					set formnum to cell "form num" of current record of database "test Gang"
				end tell
				--add if..else here?
				tell application "Finder"
					activate
					select folder "untitled folder" in folder myvendor of disk "Apps"
					set name of selection to formnum -- ran through but came up with an error saying that last form number was already used needs an if...then
				end tell
				--Applescript will find file from control number in FMP and move that file to new folder
				tell application "FileMaker Pro"
					set myversion to cell "version info" of current record of database "Test Gang"
				end tell
				tell application "Finder"
					activate
					select file myversion of folder "Test Files" of disk "Apps"
					--if file myversion is not in folder "Test Files" of disk "Apps" then -- added 2/22/02
					--display dialog "File Missing!" buttons {"Find File", "Cancel"} default button "Find File" -- added 2/22/02
					--else -- added 2/22/02
					move selection to folder formnum of folder myvendor of disk "Apps"
					--end if -- added 2/22/02
				end tell
				repeat with i from 1 to the_number_of_records
					try
						tell application "FileMaker Pro"
							set formnum to cell "form num" of current record of database "Test Gang"
							go to record i
							set formnum2 to cell "form num" of current record of database "Test Gang"
							if formnum = formnum2 then
								tell application "FileMaker Pro"
									set myversion to cell "version info" of current record of database "Test Gang"
									tell application "Finder"
										activate
										select file myversion of folder "Test Files" of disk "Apps"
										move selection to folder formnum of folder myvendor of disk "Apps"
									end tell
								end tell
							else if formnum is not  equal to formnum2 then
								tell application "Finder"
									select folder myvendor in disk "Apps"
									make new folder in folder myvendor of disk "Apps"
									tell application "FileMaker Pro"
										go to record i
										set formnum to cell "form num" of current record of database "test Gang"
										tell application "Finder"
											activate
											select folder "untitled folder" in folder myvendor of disk "Apps"
											set name of selection to formnum
											tell application "FileMaker Pro"
												set myversion to cell "version info" of current record of database "Test Gang"
												tell application "Finder"
													activate
													select file myversion of folder "Test Files" of disk "Apps"
													move selection to folder formnum of folder myvendor of disk "Apps"
												end tell
											end tell
										end tell
									end tell
								end tell
							end if
						end tell
					end try
				end repeat
			end if --added 02/22/02
		end repeat
	end tell
	end timeout 
end tell
beep

Keith, I may not be the best person to comment any further - I don’t have FMP. You make no reference to my earlier comment. Have I misunderstood something?
Andreas

Sorry. My bad. This is part of it, the original script is pretty long.

repeat with i from 1 to the_number_of_records
try
tell application "FileMaker Pro"
set formnum to cell "form num" of current record of database "Test Gang"
go to record i
set formnum2 to cell "form num" of current record of database "Test Gang"
if formnum = formnum2 then

: Unless you have made alterations to your script for this posting
: then it makes no sense to me. Having set formnum and
: formnum2 to exactly the same value it does not make sense to
: ask if they equal each other, does it?

formnum is the data from first record’s field “form num” formnum2 is the data from the second record’s field “form num” so the data would be different

: Do you actually mean cell “form num” , i.e. a cell
: named “form num” or did you intend cell formNum ,
: the cell whose number is (the number in the variable formNum)?

a cellnamed “form num”
sorry Keith

: Andreas

Quite right, Keith, I should have realised.
Two points:
1 You must admit that the whole thing is a bit complex - reading it is a bit like tracing the path of one piece of spaghetti across the plate! It might help if you left the computer aside and drew out on a piece of paper the ‘flow-chart’ for what should happen.
2 The loop is set to repeat while myvendor has a certain value. I must confess that I haven’t spotted anything that will alter its value. That could, though, be because some of the sauce got in my eye!
Andreas

I was waiting to see your response to my last post. Was I right - have you created a loop with no exit?
Anyway, as it’s fresh in my mind the next thing I was going to say was:
You seem to be making your poor old Mac do an awful lot of running to and fro - go to FMP, get “a”, come back to the Finder, do “the biz” with “a”, now go to FMP again, get “b”, bring it back to the Finder, do “the biz” with it, go back to FMP.
It’s a bit like bringing water back from the well with a teaspoon. Why not use a bucket so that you only have to go there once, bringing back {a,b,c,d…}. Then you just tell the Finder once to do “the biz” - with each item in the bucket in turn. Hope that makes sense. Let us know how you get on.
Andreas

The following few lines are terribly simple - forgive me if they are too much so, but I hope they might just help…

-- Create pretend data (pseudo FMP). Just for this exercise - not for your program.
set FMPdata to {1234, "abcd", 9876, "Hello"}
-- We go to FMP and collect the data we need
set mySausage to {}
repeat with x from 1 to FMPdata's length
    set mySausage to mySausage & FMPdata's item x
end repeat
-- We take the sausage to the Finder
tell application "Finder"
    repeat with fName in mySausage
        make new folder at desktop with properties {name:fName}
    end repeat
end tell

Some bright spark will be tempted to write to say that ‘mySausage’ isn’t needed because it’s the same as ‘FMPdata’. That is irrelevant here - this is a learning exercise and an attempt to get you thinking about methodology.
Keep turning the handle!
Andreas

: I was waiting to see your response to my last post. Was I right -
: have you created a loop with no exit?
: Anyway, as it’s fresh in my mind the next thing I was going to
: say was: You seem to be making your poor old Mac do an awful
: lot of running to and fro - go to FMP, get " a ", come back to
: the Finder, do “the biz” with " a ", now go to FMP again, get
: " b ", bring it back to the Finder, do “the biz” with it, go
: back to…
: It’s a bit like bringing water back from the well with a
: teaspoon. Why not use a bucket so that you only have to go
: there once, bringing back {a,b,c,d…}. Then you just tell the
: Finder once to do “the biz” - with each item in the bucket in
: turn. Hope that makes sense. Let us know how you get on.
: Andreas
Yes you’re right I made a loop with no end. I tried other loops like repeat until current record = the_number_of_records but that broke the script. I was thinking that I could set the_number_of_records to the number of records in the database then have it stop after it reaches the last record. I’m not sure how to do this though. Of course I am new to AppleScript and I am pulling my hair out.
The list may be helpful if I can figure out what I need to put in them. Should I put the variables that I need to make as a folder and file I need to move from each record into the list? Thank you so much, I know I’m a PITA (Pain In The A$$), but I’m learning AppleScript through error and a few books)
Keith

Andreas, I did clean up the calls to FMP and the Finder Now I have FMP set the variables at one time. It removed a few lines, I’ll try a little bit more.
Thanks
Keith

Hey I fixed the loop. After searching the books a little deeper, I realized I had one more loop than I needed. I will still look at the FMP lists you showed me, they may be helpful. Now if only I can convince the script to move a file that has .pdf at the end instead of just the selected variable “myversion” Hopefully this will be simple or I may need to rename the files i wish to collect.

Thanks Again

: The following few lines are terribly simple - forgive me if they
: are too much so, but I hope they might just help… –
: Create pretend data (pseudo FMP). Just for this exercise - not
: for your program.
: set FMPdata to {1234, “abcd”, 9876, “Hello”}
: – We go to FMP and collect the data we need
: set mySausage to {}
: repeat with x from 1 to FMPdata’s length
: set mySausage to mySausage & FMPdata 's item x
: end repeat

: – We take the sausage to the Finder
: tell application “Finder”
: repeat with fName in mySausage
: make new folder at desktop with properties {name : fName}
: end repeat
: end tell
: Some bright spark will be tempted to write to
: say that ‘mySausage’ isn’t needed because it’s the same as
: ‘FMPdata’. That is irrelevant here - this is a learning
: exercise and an attempt to get you thinking about methodology.

: Keep turning the handle!

: Andreas