mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
Would this write the whole line to a file then...

Code:
else {
    sockread &temptext
    write <filename> $bvar(&temptext,0)
  }
}

Ninko #195613 27/02/08 11:23 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You can't use /write. You have to use /bwrite, as mentioned.

To overwrite the text in the file:
/bwrite filename.txt 0 -1 &temptext

To append the data to the end of the file:
/bwrite filename.txt -1 -1 &temptext

In either case, you're better off removing the file before writing to it so you make sure you only have the data from the variable in the file.


Invision Support
#Invision on irc.irchighway.net
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
Strange, using /bwrite filename.txt 0 -1 &temptext has messed up the data. It's as though its only reading random parts of the line

Code:
on *:sockread:test:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    sockread &temptext
    /bwrite filename.txt 0 -1 &temptext
  }
}


Maybe its reading the line from the sock to quick or something?

Last edited by Ninko; 27/02/08 11:41 PM.
Ninko #195619 28/02/08 01:52 AM
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Im really loving binvars, this is roughly what I do.

Binvars handle the line byte by byte, or character by character. You can change it to a text result with the $bvar(&var,N).text where the N stands for the byte number.

1 is the 1st character or byte. 2 is the second character or byte. 32 is the 32nd character in the line and so on. So if I say $bvar(&var,48-).text, it will return everything from character 48 on in plain text format. (Read the mirc help file for more information.)

Lets say Im searching for an email address in a very long line.

I first have the sockread echo to a window so I can find what to look for. echo -a $bvar(&var,1-).text

Let's say I want to retrieve the "mailto" address from a page. First I find the email address in the code.

<a class="no-textdecoration-white" href="mailto:webmaster@email.com">Contact Webmaster</a> -

Then I look for something before the address that only exists in this one place and nowhere else on the whole page. Let;s say I got lucky and "mailto:" only exists on this one line.

As starbucks Mafia pointed out, you sockread -f to a &binvar. We will name it &var.

sockread -f &var

Then use $bfind to find "mailto:".

if ($bfind(&var,1-,mailto:)) {

This starts at character 1 and searches everything after. (1-)

;It's found mailto: and now gives me the byte number for the first character in my search string. "m" is the 41st character.

Quote:
<a class="no-textdecoration-white" href="m



So now I know that $bvar(&var,41).text == m. I also know that there are 7 characters in mailto: so 41 + 7 is the first character of the email address. I set this number (41 + 7) as a local variable and then I search for the end of the email address.

As you can see, mailto:webmaster@email.com" , it has a " at the end of it. So what I do is start my search from the beginning of the email address and search for the next " and set the number as the 2nd local variable.

(Binvars allow you to search for ascii characters or plain text characters.)

So this is how I do it.

Code:
if ($bfind(&var,1-,mailto:)) {

var %em_1 = $calc($ifmatch + 7), %em_2 = $bfind(&var,%em_1,")

echo -a Email Address is $bvar(&var,%em_1,%em_2).text !

}


Ok so now I know the last number of the email address. (%em_2)
If I need to search for anything else in this line I will start my search from this number doing it the same way.

This may not be the best way of using binvars but this is how I figured it out. I hope it makes sense. mIRC help file has a lot to say about using binvars and the identifiers that help you.

Ninko #195620 28/02/08 02:00 AM
Joined: Aug 2003
Posts: 144
M
Vogon poet
Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
Hi.

No the things is that the bwrite command has several option on it.

bwrite filename.txt S N &TempText

The S is the Start Position to bwrite the new information
If S is -1, the informations are appended to the end of the file
If S is 0, the file is cleaned and the informations are appended to the file ( that has no information )

Hope i have help you.
Good luck

Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
Hi all,
Sorry for the late reply. Thank you very much DJ_Sol, I'm finally starting to get it now lol. Thanks to everyone else who also replied!


Ninko

Page 2 of 2 1 2

Link Copied to Clipboard