Examples: Import_GetNextField()


The following example opens a text file for importing. It returns a pathname using the getfile() function, then opens the file for that pathname using the Import_OpenFile() function. The script then loops through each record in the file using Import_GetNextRecord(), and returns field values for each record using Import_GetNextField(). Once processing reaches the end of the file, or if the script encounters an error, the script closes the text file using Import_CloseFile().

local integer l_num_fields,l_file_ID,l_result,l_index,l_delimiter;
local string l_pathname, l_text;
local boolean l_EOF;

l_delimiter = COMMAFILE; {Comma delimited.}

if getfile("Choose an import file:", TEXTFILE, l_pathname) then
	l_file_ID = Import_OpenFile(3333, l_pathname, l_delimiter, l_num_fields);
	{Display the pathname in the window.}
	'(L) TextFile_Pathname' = l_pathname;
	{Check for errors opening the file.}
	if (l_file_ID = 0) or (l_num_fields = 0) then
		{The file couldn’t be opened.}
		warning "There was an error opening the text file.";
		{Release the file ID.}
		l_result = Import_CloseFile(l_file_ID);
		abort script;
	end if;
	{Loop through the file to examine each record.}
	l_EOF = Import_GetNextRecord(l_file_ID);
	while not l_EOF do
		{Loop through each record to get field values.}
		for l_index = 1 to l_num_fields do
			l_text = Import_GetNextField(l_file_ID);
			warning l_text;
		end for;
		l_EOF = Import_GetNextRecord(l_file_ID);
	end while;
	l_result = Import_CloseFile(l_file_ID);
end if;

Documentation Feedback