Page 1 of 1 1
Topic Options
#35534 - 2003-01-22 08:27 PM Length of Line?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
Trying to write to a file with fixed length fields... the problem is lets say I want to write a particular variable at the beginning of the line but in position X I need to write my next field. I know how to get the length of the variable but how do I write spaces after the variable to take up the right space?

Does that make sense...

Lets say...
Len($Something) = 10

I need to write
$Something then in position X need to write the next field...

I know I am missing something here so can someone clue me in?

Thanks
_________________________
Austin Henderson

Top
#35535 - 2003-01-22 08:33 PM Re: Length of Line?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
code:
$fixed=100 ;everyfield is fixed to width 100
$line="whatever"
$fixed_line=$line
for $c=1 to $fixed-len($line)
$fixed_line=$fixed_line+" "
next

should do.
_________________________
!

download KiXnet

Top
#35536 - 2003-01-22 08:36 PM Re: Length of Line?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
How about PadStr() UDF?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#35537 - 2003-01-22 08:36 PM Re: Length of Line?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
Darn.. brain fart.

Thanks so much.
_________________________
Austin Henderson

Top
#35538 - 2003-01-22 08:44 PM Re: Length of Line?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
didnt see UDF will check it out too..

Thanks
_________________________
Austin Henderson

Top
#35539 - 2003-01-22 08:54 PM Re: Length of Line?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sure...

and I had too much time in my hands as coded it.
_________________________
!

download KiXnet

Top
#35540 - 2003-01-22 09:32 PM Re: Length of Line?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
We know that Lonk...

Can someone please give Lonkero a scripting job that will take up a few days of boredom for him. [Big Grin]

Top
#35541 - 2003-01-22 11:00 PM Re: Length of Line?
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Austin

Isn't this a the opposite of this thread: Reading File For Processing

Are you trying to export/import files from an AS/400 or any other host ?
If this is the case, here's something to get you started on the export.

code:
Break On
$FieldStart = 1,11,51,71
; Change $FieldStart to fit the length of fields in the returned fixed record
; ubound $FieldStart is allways 1 greater than ubound $Fields because:
; Last value in $FieldStart is used to indicate the length of the last value in $Fields
; (Last value - secondlast value equals lengts of last member of $Fields)

;Loop to read fields
$Fields = 'Field1','This is a very long field','This wil be truncated because it is longer than 20 chars 71 - 51'
$FixedRec = CrtRecord($Fields,$FieldStart)
; Write $FixedRec to new file
;End Loop to read fields

Function CrtRecord($Fields,$FieldStart)
Dim $i,$L,$Field
$CrtRecord = ''
For $i = 0 To UBound($Fields)
$L = $FieldStart[$i + 1] - $FieldStart[$i]
$Field = Left($Fields[$i],$L) ; Truncate field if longer than allowed
While Len($Field) < $L ; Expand field to fit fixed length
$Field = $Field + ' '
Loop
$CrtRecord = $CrtRecord + $Field
Next
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 1067 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.11 seconds in which 0.052 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