The command ListC.ReadFile(ListC_ID, "C:\EL_CollectionsTestData.txt"); is used to read the following file in. C:\EL_CollectionsTestData.txt". The contents of the file are below.
Notice double quotes were used on strings however it turns out you do not really need them. It works either way.
Code: Select all
"John","New York",31
"Jane","Florida",25
"Carlos","Oregon",19
"Leticia","California",42
"EOF","EOF",0
Code: Select all
{ A_ELCollectionExample_CSV_read}
{
This is the input file.
It can read it with or without quotes on the string fields.
"C:\EL_CollectionsTestData.txt"
"John","New York",31
"Jane","Florida",25
"Carlos","Oregon",19
"Leticia","California",42
"EOF","EOF",0
}
variables:
MyName(""),
MyState(""),
MyAge(0),
ListName_ID(0),
ListState_ID(0),
ListAge_ID(0),
ListC_ID(0),
RecordNumber(0);
if CurrentBar = 1 then
Begin
ListC_ID = ListC.new;
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), "ListC_ID", " " , ListC_ID, " " , " ");
Value1 = ListC.ReadFile(ListC_ID,"C:\EL_CollectionsTestData.txt");
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), "File Is Read Now", " " , " ");
ListName_ID = ListC.Get(ListC_ID,1);
ListState_ID = ListC.Get(ListC_ID,2);
ListAge_ID = ListC.Get(ListC_ID,3);
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), "Get List IDs", " " , " ");
Print( File("C:\EL_Collections_Test.txt"), "ListName_ID", "=" , ListName_ID, " " ,
"ListState_ID", "=" , ListState_ID, " " , "ListAge_ID", "=" , ListAge_ID, " " , " ");
MyName = ListS.get(ListName_ID,1);
MyState = ListS.get(ListState_ID,1);
MyAge = ListN.get(ListAge_ID,1);
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), "Print first Row", " " , " ");
Print( File("C:\EL_Collections_Test.txt"), "MyName", "=" , MyName, " " ,
" MyState", "=" , MyState, " " , " MyAge", "=" , MyAge, " " , " ");
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), "Print all Rows using a while loop", " " , " ");
RecordNumber = 0;
while MyName <> "EOF"
begin
RecordNumber = RecordNumber + 1;
MyName = ListS.get(ListName_ID,RecordNumber);
MyState = ListS.get(ListState_ID,RecordNumber);
MyAge = ListN.get(ListAge_ID,RecordNumber);
if MyName <> "EOF" then
begin
Print( File("C:\EL_Collections_Test.txt"), "MyName", "=" , MyName, " " ,
" MyState", "=" , MyState, " " , " MyAge", "=" , MyAge, " " , " ");
end;
end; {while MyName <> "EOF"}
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), " ");
Print( File("C:\EL_Collections_Test.txt"), "Print last row to show the EOF (end of file) marker",
" " , " ");
Print( File("C:\EL_Collections_Test.txt"), "MyName", "=" , MyName, " " , " MyState", "=" ,
MyState, " " , " MyAge", "=" , MyAge, " " , " ");
ListC.Clear(ListC_ID);
end; {if CurrentBar = 1 then}
Here is the output of the print statements.
Code: Select all
ListC_ID 91.00
File Is Read Now
Get List IDs
ListName_ID=92.00 ListState_ID=93.00 ListAge_ID=94.00
Print first Row
MyName=John MyState=New York MyAge=31.00
Print all Rows using a while loop
MyName=John MyState=New York MyAge=31.00
MyName=Jane MyState=Florida MyAge=25.00
MyName=Carlos MyState=Oregon MyAge=19.00
MyName=Leticia MyState=California MyAge=42.00
Print last row to show the EOF (end of file) marker
MyName=EOF MyState=EOF MyAge= 0.00