mIRC Home    About    Download    Register    News    Help

Print Thread
#205025 10/10/08 01:44 AM
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
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.

Joe_Dean #205026 10/10/08 02:00 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Loop through the items using $ini and return their values using $readini.

-genius_at_work

genius_at_work #205027 10/10/08 02:06 AM
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Could you give me an example? I'm not very experienced with loops. :P

Joe_Dean #205028 10/10/08 02:08 AM
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
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?

Joe_Dean #205029 10/10/08 02:15 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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

genius_at_work #205030 10/10/08 02:22 AM
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
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

genius_at_work #205031 10/10/08 02:58 AM
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Just one more thing...

Not always are there results. How do I add an else statement or something in this?

Joe_Dean #205032 10/10/08 03:38 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
After the last } of the while loop, add this line:

Code:

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




-genius_at_work

genius_at_work #205033 10/10/08 03:45 AM
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
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.

Joe_Dean #205034 10/10/08 04:41 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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

genius_at_work #205036 10/10/08 06:38 AM
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Yep, that worked. Thanks again.


Link Copied to Clipboard