Skip to content
MSN Addons

Code for this text file

A TG007 community discussion started by nyt1972.

Discussion 52 posts
Page 1 of 3
Open
Topic #5787 · 52 published posts · 4,074 views

Hello mates,

 

I have a text file "abc.txt" having these lines:

 

1:1 Do good have well

1:2 Take your mind off the things you do not want

1:3 Put it on the things you do want

1:4 First deserve then desire

 

 

I need a code if I type the command !show 1:2 it shuld display the quote 1:2 in main, and if I type !show 1:3 it should display quote 1:3.

 

I wrote this code but its not working.


on *:TEXT:*:#: { 
 if (!show == $1) && ($2 isnum) { /msg # $read(abc.txt,$2) } 
} 

 

 

Thankx.

on *:TEXT:*:#: {
 tokenize 32 $strip($1-)
 if (!show *:* iswm $1-2) { msg $chan $read(abc.txt, s, $2) }
}

 

try that.

Thanks GD,

 

Yes its working, thankyou very much.

I got this code from rumbar site but for this code I hv to make changes in the text file and hv to put [] around the numbers, e.g [1:1] instead of 1:1

 

what to change here in the code to work with my text file.

 

on *:text:!quote [*]:#:{ 
 var %parm = $remove($2,[,]) 
 var %chapt = $gettok(%parm,1,58) 
 var %line_from = $gettok($gettok(%parm,2,58),1,45) 
 if ((%line_from !isnum) || (%chapt !isnum)) { 
   msg # error in input 
   return 
 } 
 var %line_to = $gettok($gettok(%parm,2,58),2,45) 
 if (!%line_to) { %line_to = %line_from } 
 if (%line_to !isnum) { msg # error in input } 
 while (%line_from <= %line_to) { 
   var %find = $+($chr(91),%chapt,$chr(58),%line_from,$chr(93)) 
   var %line = $read(quranenglish.txt,s,%find) 
   if ($readn == 0) { msg # No line exists for %find  } 
   else { 
     var %lines = $wrap(%line, tahoma, 11, 500,1,0), %i = 1 
     while (%i <= %lines) { 
       msg # %find $wrap(%line, tahoma, 11, 500,1,%i) 
       inc %i 
     } 
   } 
   inc %line_from 
 } 
} 

i'd recommend using tgk's snippet as the one you posted there can have errors with large files and it's more time-consuming

People are like slinkies; they're generally boring until you push them down stairs

ok thankx Angelia, but can u or anyone else edit Gtk code to get multiple lines from the text file.

 

on *:TEXT:*:#: {
tokenize 32 $strip($1-)
if (!show *:* iswm $1-2) { msg $chan $read(abc.txt, s, $2) }
}

on *:TEXT:*:#: {
tokenize 32 $strip($1-)
if (!show *:* iswm $1-2) {
 var %n = 1
 while (%n) { 
   if ($read(abc.txt, s, $2)) { msg $chan $ifmatch | inc %n }
   else { break }
 }
}

that help?

People are like slinkies; they're generally boring until you push them down stairs

good try angelia, but you would want to do the code like this.

 

on *:TEXT:*:#: {
 tokenize 32 $strip($1-)
 if (!show *:* iswm $1-2) {
   var %n = 1
   while ($read(abc.txt, s, $2, %n)) {
     msg $chan $ifmatch
     inc %n
   }
 }
}

 

this way it shouldn't freeze mIRC. With your code it would continue to do the first line and freeze up.

shouldnt the break take care of that? it's dsigned to exit the while loop

People are like slinkies; they're generally boring until you push them down stairs

arr nope, because with yours, there is no move on in the read, you just have it as if ($read... so it would find the first one, and because it always finds the first one, it would freeze up. With mine, you will see how my variable is inside the read, putting it there means that it starts with the first, then the seconds, etc. But good attempt, you are learning!

TGK, when I type !show 1:2 or !show 2:5 etc. then it works but it repeat the same line for number of times say 6 or 7 times ,

 

and it dont work for multiple line e.g if I want to show 1:2, 1:3,1:4 and 1:5 I type !show 1:2-5

Edited Jan 5, 2006 1:41 PM by nyt1972

i forgot the %n :lol: the strange thing is, when the %n is included it displays the correct line but repeats it depending on the line it's on (ie: line 5 displays it 5 times). it did that when i used tgk's too, which is the same problem nyt just mentioned.

test {
 tokenize 32 a 16
;if (!show *:* iswm $1-2) {
 var %n = 1
 while ($read(abc.txt, s, $2, %n)) {
   echo $ifmatch
   inc %n
 }
;}
}

the above returns abcdef 6 times

abc.txt contains:
11 a
12 ab
13 abc
14 abcd
15 abcde
16 abcdef
17 abcdefg
18 abcdefgh
19 abcdefghi
20 abcdefghij

see, the problem is, specifying N in this instance: $read(abc.txt, s, string, N) is not what we thoguht it to be, so, it just loops. thus, you need to use this:

on *:text:!show*:#:{
 tokenize 32 $1-
 var %n = 1
 while ($read(abc.txt,%n)) {
   if ($2 * iswm $ifmatch) { msg # $read(abc.txt,%n) | inc %n }
   else { inc %n }
 }
}

then it needs to be refined for your follow up. i gave up on that one :lol: i think regex would come in handy for that, which i'm not too great with.

 

But good attempt, TGK, you are learning!

Edited Jan 5, 2006 6:21 PM by Angelia

People are like slinkies; they're generally boring until you push them down stairs

Thank you TGK and Angelia,

 

I wrote this code just for learning, got help from the MIRC help and from your codes and it is working. thanx for helping and I will bother you pplz coz now m enjoing coding scripts.

 

on *:TEXT:!quote *:*: {
 var %l = $gettok($2,1,58)
 var %m = $gettok($gettok($2,2,58),1,45)
 var %n = $gettok($gettok($2,2,58),2,45)
 var %x = %l $+ $chr(58) $+ %m
 while (%m <= %n) {
   msg $nick $read(quotes.txt, s,%x)
   inc %m    
   var %x = %l $+ $chr(58) $+ %m
 }
}

Edited Jan 6, 2006 7:56 AM by nyt1972

anyway this is my final code, its not like u pplz but this is my first one.

 

on *:TEXT:!quote *:*: {
 var %l = $gettok($2,1,58)
 var %m = $gettok($gettok($2,2,58),1,45)
 var %n = $gettok($gettok($2,2,58),2,45)
 var %x = %l $+ $chr(58) $+ %m
 if %n == $null {
   msg $nick (I) $read(abc.txt, s,%x) (I)
 halt }
 while (%m <= %n) {
   msg $nick (I) $read(abc.txt, s,%x) (I)
   inc %m    
   var %x = %l $+ $chr(58) $+ %m
 }
}

Edited Jan 6, 2006 9:25 AM by nyt1972

arr lol, now i know why mine kept repeating.

 

on *:TEXT:*:#: {
tokenize 32 $strip($1-)
if (!show *:* iswm $1-2) {
var %n = 1
while ($read(abc.txt, s, $2, %n)) {
msg $chan $ifmatch
%n = $calc($readn + 1)
}
}
}

 

This should fix floor of constant repetition.

 

I am trying this to find lines of text under a specified heading in a text file.

 

I am trying it to reach to the heading and read it untill reached at the word end.

 

on * :TEXT:!quote *:#: {
var %x = $read(quotes.txt,w,$2)
if %x == null { 
msg $nick Sorry not found
 halt
}
while (%x != end) {
 msg $nick $read(hadith.txt)
}

have you tried using an ini file instead? it'd be so much easier

alias toini {
 var %r = 1
 while (%r <= $lines(quotes.txt)) {
   writeini quotes.ini quotes $read(quotes.txt,%r)
   inc %r
 }
}

on *:text:!quote*:#:{
 if ($remove($2,-,:) !isnum) { msg # Sorry, that's not a number | halt }
 if (- !isin $2) { msg # $2 - $readini(quotes.ini,quotes,$2) | halt }
 if (- isin $2) {
   var %n = $gettok($gettok($2,1,45),2,58)
   while (%n <= $gettok($2,2,45)) {
     var %r = $gettok($2,1,58) $+ : $+ %n
     msg # %r - $readini(quotes.ini,quotes,%r)
     inc %n
   }
 }
 else { echo -a Whoops, error in coding! }
}

that should do everything you want for quotes.txt - tried & tested. the bottom message didnt show :lol:

for your last post, an ini file would work well with that too, just edit the code above to suit.

mirc can read from ini files faster than any other file extension so it's usually the best to use

People are like slinkies; they're generally boring until you push them down stairs

arr i donno about that, if you use the $read s or $read w correctly, it can be probably just as fast as reading an ini file. The main problem with an ini file is that you are limited to 64k of information. (check /writeini). Ofcourse it does give you the option of using -n, but it would be a pain to use it every time.

Edited Jan 6, 2006 9:42 PM by The Gate Keeper

you can use the -n and it will still try to write to the ini file even if its bigger than 64k

 

and you could allways make the /writeini -n etc as an alias to save you writting it over and over

Edited Jan 6, 2006 10:00 PM by Ozzy10

My code does NOT have bugs. It just develops random features.

lol ozzy, thanks for the reptetition :P