#35475 - 2003-01-21 08:24 PM
Reading File For Processing
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
I am interested in using kix to process a file for some calculations. I understand readline and that junk but I am concerned with a delimited file. Anyone out there have any thoughts for reading a delimited file. Do I read the file by line then process the line or is there a better way to do that?
Thanks in advance.
_________________________
Austin Henderson
|
|
Top
|
|
|
|
#35477 - 2003-01-21 08:42 PM
Re: Reading File For Processing
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
How about if I were to use a fixed length file?
Thanks for the help
_________________________
Austin Henderson
|
|
Top
|
|
|
|
#35481 - 2003-01-21 11:20 PM
Re: Reading File For Processing
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
If your fixed length file dosn't have a standard fielddelimitor, you can't use split(), you wil have to supply the start position of each field in the record.
In the following code, the function: CrtFldArr() returns an array of fields in the record based on starting position of all fields in the fixed record.
code:
Break On $FieldStart = 1,11,51 ; Change $FieldStart to fit your input file ; Loop thru file $Rec = ReadLine(1) $FieldArray = CrtFldArr($Rec,$FieldStart) ; Do something with the returned fields ; End Loop thru file Function CrtFldArr($Rec,$FieldStart) Dim $Ret[0],$i,$UB,$L $UB = UBound($FieldStart) For $i = 0 To $UB ReDim Preserve $Ret[$i] If $i = $UB $Ret[$i] = SubStr($Rec,$FieldStart[$i]) Else $L = $FieldStart[$i + 1] - $FieldStart[$i] $Ret[$i] = SubStr($Rec,$FieldStart[$i],$L) EndIf Next $CrtFldArr = $Ret EndFunction
-Erik
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1607 anonymous users online.
|
|
|