mIRC Homepage
Posted By: Joe_Dean INI Help - 10/10/08 01:44 AM
How do I search though a specific INI file (let's say for example 'global.ini') for the specified value and return every item that contains that value? Example:

global.ini contains this:
Code:
[general]
yellow=23
green=89
purple=23
orange=23
red=19


If I type !search 23, I want the script look inside global.ini and return all items with a value of '23'. So if I typed this, the script should return:
Yellow
Purple
Orange

Any help is appreciated. Thanks.
Posted By: genius_at_work Re: INI Help - 10/10/08 02:00 AM
Loop through the items using $ini and return their values using $readini.

-genius_at_work
Posted By: Joe_Dean Re: INI Help - 10/10/08 02:06 AM
Could you give me an example? I'm not very experienced with loops. :P
Posted By: Joe_Dean Re: INI Help - 10/10/08 02:08 AM
ehh, sorry to double post, but just to make sure we're clear, you do know I'm not interested in returning the values, but the name of the items, correct?
Posted By: genius_at_work Re: INI Help - 10/10/08 02:15 AM
Example:

Code:

var %file = mydata.ini
var %sect = mysection
;---------------------

var %x, %i = 0, %ii = $ini(%file,%sect,0)
while (%i < %ii) {
  inc %i
  %x = $ini(%file,%sect,%i)
  if ($readini(%file,%sect,%x) == $1) {
    echo -a Matched $1 @ %x
  }
}



Change %file and %sect to match your ini filename and ini section(topic).

-genius_at_work
Posted By: Joe_Dean Re: INI Help - 10/10/08 02:22 AM
There's people that are professional scriptors and then there's the ones who just friggin pwn at scripting, much like yourself.

Thanks man, I really appreciate your help. smile
Posted By: Joe_Dean Re: INI Help - 10/10/08 02:58 AM
Just one more thing...

Not always are there results. How do I add an else statement or something in this?
Posted By: genius_at_work Re: INI Help - 10/10/08 03:38 AM
After the last } of the while loop, add this line:

Code:

if (%x == $null) { echo -a No Matches Found }




-genius_at_work
Posted By: Joe_Dean Re: INI Help - 10/10/08 03:45 AM
I've tried many things and the things I tried ending up making it say 'no matches' when there ARE results and when there AREN'T results. But doing what you said...

Code:
while (%i < %ii) {
          inc %i
          %x = $ini(%file,%sect,%i)
          if ($readini(%file,%sect,%x) == $2) { .notice $nick $cl %x }
        }
        if (%x == $null) { .notice $nick $cl No matches }


...doesn't work. If there ARE matches, it shows all matches and doesn't say "no matches". If there AREN'T matches, it doesn't show anything.
Posted By: genius_at_work Re: INI Help - 10/10/08 04:41 AM
Try this:

Code:

var %file = mydata.ini
var %sect = mysection
;---------------------

var %x, %m = 0, %i = 0, %ii = $ini(%file,%sect,0)
while (%i < %ii) {
  inc %i
  %x = $ini(%file,%sect,%i)
  if ($readini(%file,%sect,%x) == $1) {
    %m = 1
    echo -a Matched $1 @ %x
  }
}
if (%m == 0) { echo -a No Matches Found }



-genius_at_work
Posted By: Joe_Dean Re: INI Help - 10/10/08 06:38 AM
Yep, that worked. Thanks again.
© mIRC Discussion Forums