Page 1 of 1 1
Topic Options
#27187 - 2002-08-16 06:52 AM Bug in Script
pommie Offline
Fresh Scripter

Registered: 2002-02-01
Posts: 27
Can somebody please tell me where Ive gone wrong with the script?
It writes the readline value multiple times, when it shoudl only write it once when the value is the same.

Also the line i'm reading is something like value=123
Is it possible to obtain just the 123, as readline takes the whole line?

Thanks

$file="c:\temp\last.cfg"
$search_for_line="lcfd_version"

IF Open(1, $file) = 0
$Version = ReadLine(1)
WHILE @ERROR = 0

IF (Instr($Version,$search_for_line) = 1)
If Open(5,"\\servername\share$\@wksta.csv",5)=0
$RC=WriteLine(5,"$version")
$RC=Close(5)

Endif
Endif

$Version = ReadLine(1)
LOOP
Close (3)
ELSE

Top
#27188 - 2002-08-16 10:32 AM Re: Bug in Script
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You may use InStr() or Split() to get the two parts of an assignment.

Using InStr():
code:
$sLine="value=123"
$iEqualIndex=InStr($sLine,"=")
If $iEqualIndex
$sParameter=SubStr($sLine,1,$iEqualIndex-1)
$sValue=SubStr($sLine,$iEqualIndex+1,9999)
EndIf
"Parameter '" $sParameter "' is assigned value '" $sValue "'" ?

Using Split():
code:
$sLine="value=123"
$asAssignment=Split($sLine,"=")
If UBound($asAssignment)
"Parameter '" $asAssignment[0] "' is assigned value '" $asAssignment[1] "'" ?
EndIf

One reason you may be getting multiple lines is that Open() will not truncate an existing file. Each time you run the script the output will be appended to existing data. If you run the script three times you will get the line three times in the file.

Consider deleting the output file before you start.

Top
#27189 - 2002-08-17 12:28 AM Re: Bug in Script
Breaker Offline
Hey THIS is FUN
*****

Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
I agree with everything Richard said. I will also add...

...or consider using RedirectOutput(), which can write to a file, overwriting its previous contents.
_________________________
================================================
Breaker


Top
#27190 - 2002-08-16 02:52 PM Re: Bug in Script
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I notice you Open(1) but Close(3)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

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 1636 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.057 seconds in which 0.03 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