Page 1 of 1 1
Topic Options
#35475 - 2003-01-21 08:24 PM Reading File For Processing
Austin Offline
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
#35476 - 2003-01-21 08:27 PM Re: Reading File For Processing
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
There is no junk in KiXtart!

You use READLINE to read the delimited lines and use SPLIT to separate them.
_________________________
There are two types of vessels, submarines and targets.

Top
#35477 - 2003-01-21 08:42 PM Re: Reading File For Processing
Austin Offline
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
#35478 - 2003-01-21 08:43 PM Re: Reading File For Processing
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You still have to use READLINE.
_________________________
There are two types of vessels, submarines and targets.

Top
#35479 - 2003-01-21 09:02 PM Re: Reading File For Processing
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mm...
or readfile() udf...

but in this case, learning how readline and kix-file-i/o works, is the most important thing so readline is the best option.
_________________________
!

download KiXnet

Top
#35480 - 2003-01-21 09:57 PM Re: Reading File For Processing
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
See also the FAQ

Topic: File Input/Output Primer
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#35481 - 2003-01-21 11:20 PM Re: Reading File For Processing
kholm Offline
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
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.058 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org