mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 7
P
Postino Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
P
Joined: Dec 2002
Posts: 7
Hello everyone,
I'm stumped as to why the following is not working. First let me explain what the code is supposed to do:
I have a text file, which contains approximately 90,000 lines (quotes).
I wanted to be able to let people enter a few words, and search the text file for that string and display the result. I realize right now it only does an echo, because I didn't want to flood the channel with silly things as I was trying to work.

Code:
 
on *:TEXT:*:*: {

  if (quote isin $2) {
    %posty.search.string = $strip($4-)
    var %posty.asterisk = *
    var %posty.length = $len(%posty.search.string) - 1

    %posty.search.string = $left(%posty.search.string,%posty.length)
    %posty.search.string = $right(%posty.search.string,-4)
    %posty.search.string = %posty.asterisk $+ %posty.search.string $+ %posty.asterisk
    %posty.search.string = $strip(%posty.search.string)
    echo -s Now searching for %posty.search.string
    %posty.answer = $read($mircdirquotes.txt, w, %posty.search.string)
    echo -s Result %posty.answer
  }
}
 


I realize it is not optimized in any way, but the result of this exercise is that I get no results.
The strange thing is the following:
If I copy and paste the %posty.search.string in to the Find dialog box in my text editor I get no results either, but if I type the text, exactly as I see it, it finds it. I $strip the code and yet there seems to be something there that is throwing off the result.
If you are wondering why I'm trimming it left and right, is because sometimes people enter extra space or a question mark, so I figured I would remove them before I added the asterisk for the wildcard search for $read.
Any help, suggestion, nudge in the right direction will be very much appreciated smile
Thank you.

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
on *:TEXT:*:*:{

  if (quote isin $2) {
    var %posty.search.string = $+(*,$right($left($strip($4-),-1),-4),*)
    echo -s Now searching for %posty.search.string
    var %i = 1
    while ($read($mircdirquotes.txt,ntw,%posty.search.string,%i)) {
      var %i = $readn + 1
      echo -s Results $v1
    }
  }
}


* code untested *
* code unoptimized * I would suggest you explore using /filter (from file to file) and then /play

--correction made--
Thanks to me looking at Russels code, i corrected mine, i was using %i thinking it was match number, rather than linenumber to start search from.

Last edited by DaveC; 18/03/06 10:07 PM.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
First off, I see that you're using a simple * wildcard in the matchtext portion of your on text event, so that will accept anything as an entry. I also see that $2 must contain the word QUOTE, therefore if someone enters QUOTE <word> it will not match, since QUOTE would be in $1 not $2

Along those same lines the search word(s) have to be in $4 (according to your code), yet, by my example, the word would be in $2.

Also please remember that you can't activate an ON TEXT event yourself, per the help file regarding the ON TEXT event.

Try this
Code:
 on *:text:!search quote*:#:{
if !$3 { .notice $nick Format is !search quote &lt;search word(s)&gt; }
else {
var %posty.search.string = $strip($3-)
%posty.search.string = $gettok(%posty.search.string,2-,32)
%posty.search.string = $gettok(%posty.search.string,-1-,63)
%posty.answer = $read(quotes.txt,ntw,$+(*,%posty.search.string,*))
if !%posty.answer { .describe # Sorry $nick, no matches for your search }
else {
var %answer
describe # $nick here are the results of your search
while $read(quotes.txt,ntw,$+(*,%posty.search.string,*),$calc(%answer + 1)) {
.msg $chan $read(quotes.txt,ntw,$+(*,%posty.search.string,*),$calc(%answer + 1))
%answer = $readn
}
}
}
 

Joined: Dec 2002
Posts: 7
P
Postino Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
P
Joined: Dec 2002
Posts: 7
Thank you to both of you... I got the problem solved thanks to you guys' snippets!

Your help is very much appreciated smile

Thank you once again


Link Copied to Clipboard