Parse to Arrays

This takes a block of field and record delimited text and parses it to arrays of various types. Lets say you have a small tab delimited text file with name, invoice number, invoice date and amount. Read the file then pass it along with pointers to the arrays to ParseToArrays and the arrays will be filled with the proper type of data, almost as if the Keebler Elves had done the work for you.

Here's some example code:
Array Text(aName;0)
Array String (14;aInvoiceNumber;0)
Array Date(aInvoiceDate;0)
Array Real(aInvoiceAmount;0)
(Where $Text is the tab delimited text from a spreadsheet or an import or maybe Santa!)

ParseToArrays calls ParseToArray and ArrayResize which can be found on the previous page.
  ` ParseToArrays
  ` Parses text to multiple arrays
  ` The arrays can be Text, String, Date or Boolean


$FirstArrayNdx:=4  ` The first array pointer is the 4th parameter

ARRAY TEXT(aParseToArrays_OuterText;0)
$LineCount:=ParseToArray ($Text;->aParseToArrays_OuterText;$RD)
$ArrayCount:=Count parameters-$FirstArrayNdx+1

For ($Ndx;1;$ArrayCount)  ` Resize all the arrays
  ArrayResize ($LineCount;$ArrayPtr)
End for 

For ($Line;1;$LineCount)
  ARRAY TEXT(aParseToArrays_InnerText;0)
  $FieldCount:=ParseToArray ($LineText;->aParseToArrays_InnerText;$FD)
  For ($FieldNdx;1;$FieldCount)
    If ($FieldNdx<=$ArrayCount)  ` ($ArrayNdx<=Count parameters)
      Case of 
        : (($Type=String array) | ($Type=Text array))
        : (($Type=Real array) | ($Type=Integer array))
        : ($Type=LongInt array)
          If ((Position(":";$Cell)>0) | (Position("AM";$Cell)>0) | (Position("PM";$Cell)>0))
          End if 
        : ($Type=Date array)
        : ($Type=Boolean array)
          If (($Cell="T@") | ($Cell="1") | ($Cell="On") | ($Cell="Y@"))
          End if 
            ` For the ones that can't be converted (2D; Picture;Pointer)
      End case 
    End if 
  End for 
End for 

ARRAY TEXT(aParseToArrays_OuterText;0)
ARRAY TEXT(aParseToArrays_InnerText;0)