Scripting Additions Guide
Table Of Contents
CHAPTER 2
Scripting Addition Commands
Using Read/Write Commands 73
display dialog errString
close access x
end try
on ReadRecord(numberOfFields, whichRecord, fieldDelimiter, ¬
recordDelimiter, fileRefNum)
try
(* if there’s a record delimiter, read all fields except for
last using field delimiter, then read last field using record
delimiter *)
if recordDelimiter is "" then
set readxTimes to numberOfFields
else
set readxTimes to numberOfFields - 1
end if
repeat whichRecord times
set recordData to {}
repeat (readxTimes) times
set recordData to recordData & ¬
{(read fileRefNum before fieldDelimiter)}
end repeat
if readxTimes is not numberOfFields then
set recordData to recordData & ¬
{(read fileRefNum before recordDelimiter)}
end if
end repeat
return recordData
on error errString number errNum
display dialog errString
return errString
end try
end ReadRecord
The script in Listing 2-1 begins by using the Choose File command to allow
the user to choose the text file that contains the desired record. After initializing
the variable into which the record will be read, the script uses the Open
for Access command to open the file and the ReadRecord handler to read a
specific record.