mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2004
Posts: 2
T
Targy Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
T
Joined: Apr 2004
Posts: 2
Hi!

I dont realy know much about mirc scripting but i made a program wich logs temperature via gameport to a file. Now I would like to ask you guys for a help. I need a script which will check how many lines the file has and reads the last line to a chan. The line in my log file looks like this "20:09:43,583","9.4.2004","","20,56","","" Is it possible to read only time date and the temperaure ? ty in advance.

TGT

Joined: Dec 2002
Posts: 102
M
Vogon poet
Offline
Vogon poet
M
Joined: Dec 2002
Posts: 102
You can use $lines(filename.txt) to see how many lines are in the file. Or $read(filename.txt,$lines(filename.txt)) to read the last line of the file. You can then use $gettok() to get the appropriate group of data.

If you're not familiar with how tokens work the main thing to know is that you can choose what character to use as a separator for the data, it looks like you may want to use commas (,) and double quotes (") which are Ascii characters 44 and 34 respectively.

$remove($gettok($read(filename.txt,$lines(filename.txt)),1,44),") <-- should return the time: 20:09:43

$gettok($read(filename.txt,$lines(filename.txt)),3,44) <-- should give you the date: 9.4.2004

$gettok($gettok($read(filename.txt,$lines(filename.txt)),6,34),1,44) <-- should be the first number (I'm assuming that's the low temp?) 20

$gettok($gettok($read(filename.txt,$lines(filename.txt)),6,34),2,44) <-- should be the other number, 56.

NOTE: "Should", I haven't tested this code, it may require fine tuning.


-
MIMP
Joined: Apr 2004
Posts: 2
T
Targy Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
T
Joined: Apr 2004
Posts: 2
Thank you alot. It works just fine but I still have a problem.
Sometimes it just doesnt print date or temperature because the line in filename.txt is not completed (still writing to it) Sometimes I just get TIME like 12:3 except 12:34:42 etc. What to do that script reads or checkes if line is full or just reads the last but one or a line 10 seconds ago.

Last edited by Targy; 10/04/04 10:19 AM.
Joined: Dec 2002
Posts: 102
M
Vogon poet
Offline
Vogon poet
M
Joined: Dec 2002
Posts: 102
You should be able to check and see if:

$gettok($gettok($read(filename.txt,$lines(filename.txt)),6,34),2,44)

returns a value. If so the line would be complete otherwise you can pull the data using:

$read(filename.txt,$calc($lines(filename.txt) - 1))


-
MIMP

Link Copied to Clipboard