Filemaker doesn't compile the read from a file

Hi everybody!

I’m trying - for the first time - to use AppleScript to import QIF file in a personal FileMaker 7 database.
I’ve done some work with script editor to simulate the writing affair, with this NOT complete script, but when I put this in Filemaker, it doesn’t compile : what’s wrong with it? Is there a workaround?

Code:

on ScriviRecord(DataOperazione, Importo, Causale, Nota)
tell application “Finder”
try
–Scrivo il record nel db di FileMaker
display dialog DataOperazione & return & Importo & return & Causale & return & Nota

	on error theErrorMessage number theErrorNumber
		display dialog "Errore in 'ScriviRecord':" & return & theErrorMessage & " (" & theErrorNumber & ")"
	end try
end tell

end ScriviRecord

on LeggiFile()
try
tell current application to activate
– Scelta file
set theFile to choose file with prompt “Scegli un File QIF:” default location (path to desktop folder) without invisibles
set fNum to open for access theFile
on error theErrorMessage number theErrorNumber
display dialog “Errore in ‘LeggiFile’:” & return & theErrorMessage & " (" & theErrorNumber & “)”
close access file theFile
return
end try
try
–Inizializzo Variabili
set theLine to “”
set DataOperazione to “”
set Importo to “”
set Causale to “”
set Nota to “”

	--Leggo il contenuto del file
	set ct to (get eof fNum)
	repeat with i from 1 to ct
		set theChar to read fNum from i to i
		set theASCII to ASCII number theChar
		if not ((theASCII is 13) or (theASCII is 10)) then
			set theLine to theLine & theChar
		else
			--Linea finita
			if theASCII is 13 then --return
				--Riconosco il tipo di linea
				set firstChar to character 1 of theLine
				if ((length of theLine) > 1) then
					set myData to (characters 2 thru (length of theLine) of theLine as string)
				else
					set myData to ""
				end if
				if (firstChar = "!") then
					--Prima linea: da ignorare!
				else if (firstChar = "D") then
					--Data Operazione
					set DataOperazione to myData
				else if (firstChar = "T") then
					--Importo
					set Importo to myData
				else if (firstChar = "N") then
					--??
				else if (firstChar = "L") then
					--Causale
					set Causale to myData
				else if (firstChar = "M") then
					--Nota
					set Nota to myData
				else if (firstChar = "^") then
					--Scrittura Record
					ScriviRecord(DataOperazione, Importo, Causale, Nota)
					--Reinizializzo le variabili
					set DataOperazione to ""
					set Importo to ""
					set Causale to ""
					set Nota to ""
				end if
			else
				--Reinizializzo la linea
				set theLine to ""
			end if
		end if
		
	end repeat
	close access fNum
on error theErrorMessage number theErrorNumber
	display dialog "Errore in 'LeggiFile':" & return & theErrorMessage & " (" & theErrorNumber & ")"
	close access fNum
end try

end LeggiFile

LeggiFile()
:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(;);):wink:
:frowning:

Model: Mac g5 2x2GHz
Browser: Safari 416.12
Operating System: Mac OS X (10.4)

To answer your subject line, FileMaker won’t compile the “read” command; I don’t know why. But you can just:
tell app “Finder” to set theTxt to (read theFile)

Thank You, Fenton.
I rewrote some piece of code including the statement ‘Tell application “Finder”’ …… ‘end tell’ and now it works… really slowly, but it’s just a step over!
:confused:

I think FM is trying to compile one of the lots of things starting with “read” in the enumerations for the “access” property of records/tables/etc.
The default target in FM is allways FM itself (that’s why you can compile “record 1” out of a FM tell-block).
As Fenton said, you must move the “read” command out of the scope of FM. You can redirect the command to a third-party app (as the Finder) or use this:

run script "read blah"

I use the last one, as redirecting commands to other apps could cause unexpected results (you’re safe in 10.2 or higher, but IIRC this would crash your app -or FM- in lower versions of the OS).

Thank you again to Fenton and jj.
The way Fenton explained me now works - but it is slow.
I haven’ understand what jj told me about the run script way; I tried this way:

but it doesn’t work… The same for:

and for:

What am I doing wrong?

Thanks in advance