Page 1 of 1 1
Topic Options
#18668 - 2002-03-14 11:32 AM Need help "remove value from ini file"
cellnet Offline
Starting to like KiXtart

Registered: 2002-02-26
Posts: 115
Loc: Sweden
Hello

Are running the following code (thanks to Bryce)

$database = "c:\database.ini"
$adresslist = readprofilestring("$database","adresslist","Script")
if instr("$adresslist","@ADDRESS") <> 0
? "Running Script"
;
; Remove @address after script starts ;
;
goto end
endif
? "Not running script...."
:end
exit

*****
If the @adress is found, I would like to remove it, after the script has started.

Any ideas

\erik

Top
#18669 - 2002-03-15 12:23 AM Re: Need help "remove value from ini file"
Mark Bennett Offline
Getting the hang of it

Registered: 2001-10-10
Posts: 70
You could either use WriteProfileString OR if you want the line deleted all together use Open and ReadLine to recreate a new instance of the file. Read each line and use SubStr to look for what you want to delete. If the line doesn't match write it into the new version then when you do get a match (ie you are at the line you want to delete) don't write it in.
Hope this makes sense.

Top
#18670 - 2002-03-15 12:38 AM Re: Need help "remove value from ini file"
kasul Offline
Fresh Scripter
*****

Registered: 2001-12-03
Posts: 41
Loc: Hannover / Germany
Hi!

How about a little "missuse" of the SPLIT function, splitting the $Adresslist with using the @ADDRESS as delimiter?

Something like this:

code:
$StripArr = SPLIT( $Adresslist , @ADDRESS )
$Stripped=""
FOR EACH $Piece IN $StripArr
$Stripped=$Stripped + $Piece
NEXT

The $Stripped would be clean of any Instances of @ADDRESS, just write that back to your .ini

nice?
_________________________
german native-> poor english sysadmin-> poor german...

Top
#18671 - 2002-03-15 12:56 AM Re: Need help "remove value from ini file"
cellnet Offline
Starting to like KiXtart

Registered: 2002-02-26
Posts: 115
Loc: Sweden
Thanks for the quick replys. Sorry Mark, I do not understand....

Added the code example
Looks like this

? "@address"

$database = "c:\database.ini"
$adresslist = readprofilestring("$database","adresslist","Script")
if instr("$adresslist","@ADDRESS") <> 0
? "Running Script"

$StripArr = SPLIT( $Adresslist , @ADDRESS )
$Stripped=""
FOR EACH $Piece IN $StripArr
$Stripped=$Stripped + $Piece
NEXT

goto end
endif
? "Not running script...."
:end
exit

Recive errors
"Running ScriptScript error : expected expression !.
$StripArr = SPLIT( $Adresslist , @ADDRESS )"

\erik

Top
#18672 - 2002-03-14 01:01 PM Re: Need help "remove value from ini file"
Mark Bennett Offline
Getting the hang of it

Registered: 2001-10-10
Posts: 70
Do you want an entry entirely removed from the INI file OR just an entry that reads Server=
Top
#18673 - 2002-03-14 01:01 PM Re: Need help "remove value from ini file"
cellnet Offline
Starting to like KiXtart

Registered: 2002-02-26
Posts: 115
Loc: Sweden
I hope I added the code sample in the right section ?

Regards
\erik

Top
#18674 - 2002-03-14 01:03 PM Re: Need help "remove value from ini file"
cellnet Offline
Starting to like KiXtart

Registered: 2002-02-26
Posts: 115
Loc: Sweden
here is the ini file

[Adresslist]
script=00010388395B

Just the @adress should be deleted

Top
#18675 - 2002-03-14 01:05 PM Re: Need help "remove value from ini file"
Mark Bennett Offline
Getting the hang of it

Registered: 2001-10-10
Posts: 70
Do a WriteProfileString on the Script setting in the Adresslist section of your Database.INI with an empty string ("").
Top
#18676 - 2002-03-14 01:07 PM Re: Need help "remove value from ini file"
cellnet Offline
Starting to like KiXtart

Registered: 2002-02-26
Posts: 115
Loc: Sweden
what will happen in case of multiple @address ?

ex

[Adresslist]
script=00010388395B,000103883NOTSAME,

Top
#18677 - 2002-03-14 01:07 PM Re: Need help "remove value from ini file"
kasul Offline
Fresh Scripter
*****

Registered: 2001-12-03
Posts: 41
Loc: Hannover / Germany
ReHi!

wich version of Kixtart do you use?
here that piece of code worked fine with V4.02 of Kix32.
I only set the $Adresslist manually

[edit]
You forgot to write the $stripped back to Your .ini:
code:
$Result = WRITEPROFILESTRING ( $database , "adresslist" , "Script" , $Stripped )

[/edit]

[ 14 March 2002, 13:19: Message edited by: kasul ]
_________________________
german native-> poor english sysadmin-> poor german...

Top
#18678 - 2002-03-14 01:08 PM Re: Need help "remove value from ini file"
Mark Bennett Offline
Getting the hang of it

Registered: 2001-10-10
Posts: 70
Should be set to empty string as Read and WriteProfileString reads after the =
Top
#18679 - 2002-03-14 01:17 PM Re: Need help "remove value from ini file"
cellnet Offline
Starting to like KiXtart

Registered: 2002-02-26
Posts: 115
Loc: Sweden
were running version 3.61. Kix in multiple location.

Old ones deleted. Now only runing version 4.02

No errors, but macaddress (@address) not disaperaring

Top
#18680 - 2002-03-14 01:19 PM Re: Need help "remove value from ini file"
cellnet Offline
Starting to like KiXtart

Registered: 2002-02-26
Posts: 115
Loc: Sweden
mark can you give a sample, not getting your idea

\erik

Top
#18681 - 2002-03-14 01:21 PM Re: Need help "remove value from ini file"
kasul Offline
Fresh Scripter
*****

Registered: 2001-12-03
Posts: 41
Loc: Hannover / Germany
Again.

Just write back the $stripped to your .ini

I edited my post above.
_________________________
german native-> poor english sysadmin-> poor german...

Top
#18682 - 2002-03-14 02:01 PM Re: Need help "remove value from ini file"
cellnet Offline
Starting to like KiXtart

Registered: 2002-02-26
Posts: 115
Loc: Sweden
Working fine, entry disapears.

But i deletes everything

Before: / database.ini /
[Adresslist]
script=0001038839

After:
[Adresslist]

Code looks like this now / correct ?

$database = "c:\database.ini"
$adresslist = readprofilestring("$database","adresslist","Script")
if instr("$adresslist","@ADDRESS") <> 0
? "Running Script"

; $StripArr = SPLIT( $Adresslist , @ADDRESS )
; $Stripped=""
; FOR EACH $Piece IN $StripArr
; $Stripped=$Stripped + $Piece
$Result = WRITEPROFILESTRING ( $database , "adresslist" , "Script" , $Stripped )


goto end
endif
? "Not running script...."
:end
exit

Top
#18683 - 2002-03-14 02:18 PM Re: Need help "remove value from ini file"
kasul Offline
Fresh Scripter
*****

Registered: 2001-12-03
Posts: 41
Loc: Hannover / Germany
re

please remove the ";" and all should be fine.

The Entry disappears if the last MAC in it is deleted, but this should be ok.
_________________________
german native-> poor english sysadmin-> poor german...

Top
#18684 - 2002-03-14 02:19 PM Re: Need help "remove value from ini file"
Mark Bennett Offline
Getting the hang of it

Registered: 2001-10-10
Posts: 70
Sorry about the confusion, if you need any other examples let me know.
Top
#18685 - 2002-03-14 02:36 PM Re: Need help "remove value from ini file"
cellnet Offline
Starting to like KiXtart

Registered: 2002-02-26
Posts: 115
Loc: Sweden
$database = "c:\database.ini"
$adresslist = readprofilestring("$database","adresslist","Script")
if instr("$adresslist","@ADDRESS") <> 0
? "Running Script"

$StripArr = SPLIT( $Adresslist , @ADDRESS )
$Stripped=""
FOR EACH $Piece IN $StripArr
$Stripped=$Stripped + $Piece
$Result = WRITEPROFILESTRING ( $database , "adresslist" , "Script" , $Stripped )


goto end
endif
? "Not running script...."
:end
exit

Sorry my mistake, working perfectly

Thank you

Greetings from sweden

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

Generated in 0.078 seconds in which 0.033 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