Archive: determine highest value in a specified section


determine highest value in a specified section
  long time ago, smile2me helped me on a script i used on an add-on for mIRC:

Function FindNumber

Exch$0
Push$1
Push$2
StrCpy$1 "0"

>loop:
>IntOp $1 $1 + 1
StrCpy$2 $0 1 $1
StrCmp$2 "=" 0 loop
StrCpy$0 $0 $1
Pop$2
Pop$1
Exch$0
FunctionEnd

Section-config
StrCpy $R9 "0"
>fileopen $0 "servers.ini" "r"

>Loop:
>fileread $0 $1
StrCmp$1 "" ExitLoop
StrCpy$2 $1 1
StrCmp$2 "n" 0 Loop
StrCpy$2 $1 "" 1
Push$2
Call FindNumber
Pop$2
IntCmp$2 $R9 Loop Loop
StrCpy $R9$2
Goto Loop

ExitLoop:
>FileClose $0
MessageBox MB_OK "The highest entry is $R8"
i'd love to use this script on the mirc.ini, which in difference to the servers.ini has various sections. the layout of mirc.ini looks like this:

[section]
n0=entry 0
n1=entry 1
n2=entry 2

[another section]
n0=entry 0
n1=entry 1
n2=entry 2

etc.

i could need a helping hand on how to modify the script above to do the following.

i need to script to do the same in a specified section, let's say determine the highest value (nX) in a section [example].

same script, different question
  i got the working script above by adding this:

ExitLoop:

>FileClose $0
IntOp $R8 $R9+ 1
WriteINIStr servers
.ini servers n$R8 "some entry"
now i want to use the last line multiple times, which of course requires a different value for $R8.


 IntOp $R8 $R9 + 1

WriteINIStr servers
.ini servers n$R8 "some entry"
>IntOp $R8 $R8 + 1
WriteINIStr servers.ini servers n$R8 "some entry"
>IntOp $R8 $R8
>
did not work (which is natural i guess). but i dont know how to solve this issue. of course i could rename the string $R8 to something different, but then i'm still limited to $R0 - $R9. is there a more elegant way to solve this (a loop maybe?).

help is highly appreciated.

First of all, please attach large scripts next time and don't open a new thread for a question that continues the one from another thread of yours.

Now, to get the highest number in a specified section I would take a different approach since the one presented here gets the highest number in the first section found that has an entry starting with "n".


StrCpy $0 0

Loop:
ReadINIStr $1 "mirc.ini" "insert desired ini section name here" n$0
IfErrors Done
IntOp$0 $0 + 1
Goto Loop

Done
: ; $0 is now the first unused number in the INI file section
>
To add entries then, all you need to do is call WriteIniStr and after each time you call it use IntOp $0 $0 + 1 to make sure the number you get is unique.

does not work, always reports "0" (i used messagebox to check this)


It works perfectly fine for me... Are you sure you have specified the right path to mirc.ini and the right section name?


i tried [section] and section , both resulted the same. if you have the time, i can send you the script via icq, you got my uin ;)


is it possible to additionally use a duplicate-filter?

n0=Leningrad
n1=Paris
n2=Madrid

at this point it wouldnt be necessary to add n3=Leningrad, since it exists already. any chance to avoid duplicates in that script?


You can compare the value you want to add with each n# and if it's already there just not add it.


hm, but what about the prefix "nX=" ?


ReadINIStr reads the value. The value doesn't include the nX=.