Page 1 of 2 12>
Topic Options
#32380 - 2002-11-13 05:28 PM extract line in file
brotons Offline
Fresh Scripter

Registered: 2002-08-23
Posts: 7
Loc: valbonne
I have file c:\toto.txt
I have will want to extract a line from this file.
The line starts with the word "disk".
And I will want to have the line in a variable $poul
thank 's

Top
#32381 - 2002-11-13 05:36 PM Re: extract line in file
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
code:
 ;test.kix;
$handle = FreeFileHandle()
$infile = "c:\toto.txt"
IF $handle > 0
IF Open($handle,$infile) = 0
$fileline = ReadLine($handle)
WHILE @error = 0
IF InStr($fileline,"disk")
$poul=$fileline
?$poul
ENDIF
$fileline = ReadLine($handle)
LOOP
Else
"File open error "+@error+" "+@serror?
EndIf
Else
"File handle error "+@error+" "+@serror?
EndIf
IF Close($handle) <> 0
"File close error "+@error+" "+@serror?
EndIf



[ 13. November 2002, 17:37: Message edited by: Waltz ]
_________________________
We all live in a Yellow Subroutine...

Top
#32382 - 2002-11-14 05:52 PM Re: extract line in file
brotons Offline
Fresh Scripter

Registered: 2002-08-23
Posts: 7
Loc: valbonne
it's ok
but I have a problem with dfsnbt.exe it does not give me information if I am not an administrator of the machine :=(

Top
#32383 - 2002-11-14 06:14 PM Re: extract line in file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Then you must run it with administrative privileges. See Installing an Application as an Admin
_________________________
There are two types of vessels, submarines and targets.

Top
#32384 - 2002-11-14 06:14 PM Re: extract line in file
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
c'est la vie... [Wink]
_________________________
We all live in a Yellow Subroutine...

Top
#32385 - 2002-11-14 06:15 PM Re: extract line in file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I actually did a Les (=sitting on my hands for a couple of minutes) before replying [Wink]

I also suspect it's a case of Better questions & happy posting

[ 14. November 2002, 18:16: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#32386 - 2002-11-14 06:17 PM Re: extract line in file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
i'm typoing withmy noser.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32387 - 2002-11-14 06:20 PM Re: extract line in file
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
So we're getting less from Jens and more from Les, more or less!
_________________________
We all live in a Yellow Subroutine...

Top
#32388 - 2002-11-14 06:22 PM Re: extract line in file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I still did deliver a quality answer.
_________________________
There are two types of vessels, submarines and targets.

Top
#32389 - 2002-11-14 07:32 PM Re: extract line in file
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
No doubts there - quality is your middle name... [Wink]
_________________________
We all live in a Yellow Subroutine...

Top
#32390 - 2002-11-14 10:55 PM Re: extract line in file
pc_g0d Offline
Fresh Scripter

Registered: 2001-11-06
Posts: 7
I personally would change Waltz's code so that it
only looked at the first four characters like so:

code:
;test.kix;
$handle = FreeFileHandle()
$infile = "c:\toto.txt"
IF $handle > 0
IF Open($handle,$infile) = 0
$fileline = ReadLine($handle)
WHILE @error = 0
$chk = LEFT($fileline,4)
IF $chk = "disk"
$poul=$fileline
?$poul
ENDIF
$fileline = ReadLine($handle)
LOOP
Else
"File open error "+@error+" "+@serror?
EndIf
Else
"File handle error "+@error+" "+@serror?
EndIf
IF Close($handle) <> 0
"File close error "+@error+" "+@serror?
EndIf

_________________________
Move out of my way or I'll replace you with a kix script.

Top
#32391 - 2002-11-14 11:05 PM Re: extract line in file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
good choice!
it's accurate.

and to have some golf change:
code:
$fileline = ReadLine($handle)
WHILE @error = 0
$chk = LEFT($fileline,4)
IF $chk = "disk"
$poul=$fileline
? $poul
ENDIF
$fileline = ReadLine($handle)
LOOP

to:
code:
	DO
$chk = LEFT($fileline,4)
IF $chk = "disk"
$poul=$fileline
? $poul
ENDIF
$fileline = ReadLine($handle)
until @error

[Wink]
_________________________
!

download KiXnet

Top
#32392 - 2002-11-14 11:06 PM Re: extract line in file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
pc_g0d: What is wrong with using INSTR()??

Your code adds one extra line and one more variable without even being more efficient.
_________________________
There are two types of vessels, submarines and targets.

Top
#32393 - 2002-11-14 11:08 PM Re: extract line in file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Golf answer:
code:
DO
IF LEFT($f,4)= "disk"
$p=$f
? $p
ENDIF
$f = ReadLine($handle)
until @error

_________________________
There are two types of vessels, submarines and targets.

Top
#32394 - 2002-11-14 11:15 PM Re: extract line in file
pc_g0d Offline
Fresh Scripter

Registered: 2001-11-06
Posts: 7
Jens,

1.Sometimes you only want a line that begins with a specific set of characters.
2.Other times you just want to find the set of characters somewhere in the line.
My code shows 1. Waltz shows 2.
_________________________
Move out of my way or I'll replace you with a kix script.

Top
#32395 - 2002-11-14 11:20 PM Re: extract line in file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jens, if the rules haven't changed, I'll improve your code...
btw, think that pc_g0d is correct on this one...

code:
DO
IF LEFT($,4)= "disk"
$p=$
? $p
ENDIF
$ = ReadLine($handle)
until @error

_________________________
!

download KiXnet

Top
#32396 - 2002-11-14 11:24 PM Re: extract line in file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
actually, he said a line, not lines...
so:
code:
DO
$ = ReadLine($handle)
until @error or LEFT($,4)= "disk"

should do.
_________________________
!

download KiXnet

Top
#32397 - 2002-11-14 11:59 PM Re: extract line in file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
code:
DO
$ = ReadLine($handle)
until not $ or LEFT($,4)= "disk"

[Big Grin]
_________________________
There are two types of vessels, submarines and targets.

Top
#32398 - 2002-11-15 12:17 AM Re: extract line in file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
huh. but, isn't that same as
code:
DO
$ = ReadLine($handle)
until not ($ or LEFT($,4)= "disk")

if yes, then it does not work.
but how goes:
code:
DO
$ = ReadLine($handle)
until LEFT($,4)="disk" or not $

_________________________
!

download KiXnet

Top
#32399 - 2002-11-15 12:17 AM Re: extract line in file
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Be nice to new users

This is the starters forum !!!

Also remember that this post might pop up from a search on the internet.

If this were my first experience with KiXtart.org, I would assume that it was a chat room for golf [Eek!]

I know I'm breaking the rules: Hijacking a post and posting in a wrong forum, BUT I was not the first

-Erik

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 601 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.144 seconds in which 0.099 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