mIRC Homepage
Posted By: HAMM3R sockets; table rows - 17/03/06 12:59 AM
I have a socket to read info from a table. I'd like to save every row to a %var. So %var would be: row1, ro2, row3. I have a working socket that can get only the first row. How can i make it continute to grab the rest of the table?
Code:
on *:sockread:blah:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %data
    sockread %data
    if (<tr><td>*</td><td>*</td><td>*</td><td>*</td><td>*</td></tr> iswm %data) { 
      echo -a $nohtml(%data)
      sockclose $sockname
      halt
    }
  }
}


Thanks
Posted By: RusselB Re: sockets; table rows - 17/03/06 04:42 AM
In your sockopen section put something like
Code:
 set %row 1 

The halt commands are unnecessary. The changes I made will store the non-html format of the line read into the variable(s). Also please note that the wildcard string that you're doing the comparison on might be matched on the very first match, so that would close the socket, even if there are more lines in the document.


Then change your sockread to
Code:
 on *:sockread:blah:{
  if ($sockerr) {
    echo -a Error.
  }
  else {
    var %data
    sockread %data
       set $+(%,row,%row) $nohtml(%data)
       inc %row
    if (<tr><td>*</td><td>*</td><td>*</td><td>*</td><td>*</td></tr> iswm %data) {
       echo -a $nohtml(%data)
       sockclose $sockname
    }
  }
}
 
Posted By: HAMM3R Re: sockets; table rows - 19/03/06 05:07 PM
Hmm. What I meant is I needed it to save the rows of the TABLE. Not the html code itself. So it needs to save it only if it matches the wildcard matchtext (signifying its part of the table). And I needed it in 1 variable, with commas seperating each row of the table. I can do that part of it. I just need it to go on to the next line of code after the match text, to see if the next line also matches. This way I can catch all of the rows in the table.
Posted By: genius_at_work Re: sockets; table rows - 19/03/06 05:31 PM
Are you sure that every line of the table has that exact format? I think it might be easier to look for <table* at the beginning and </table* at the end.

Code:
on *SOCKREAD:*:{
  var %s
  sockread %s
  tokenize 32 %s

  if (&lt;table* iswm $1-) set %intable 1
  if (%intable) {
    ;Do something with table data here
    echo -s &gt; $nohtml($1-)
  }
  if (&lt;/table* iswm $1-) unset %intable
}


(untested code)

-genius_at_work
Posted By: HAMM3R Re: sockets; table rows - 19/03/06 06:05 PM
Yes, every row in the table has the exact format of tags, just different data in place of the wildcard. The code you gave me ended up returning a few unwanted things that are scrambled in the middle of the <table> code. Could you write it using the table matchtext in my earlier post? Id appreciate it.
Posted By: genius_at_work Re: sockets; table rows - 19/03/06 06:34 PM
Try this code that I modified from RusselB's version.

[code]
on *:sockread:blah:{
if ($sockerr) {
echo -a Error.
return
}
var %data
sockread %data
if (<tr><td>*</td><td>*</td><td>*</td><td>*</td><td>*</td></tr> iswm %data) {
inc %row
set $+(%,row,%row) $nohtml(%data)
}
}

Each row is stored in variables like %row1 %row2 etc. One for each matching line of data that is sent on the socket.

-genius_at_work
Posted By: HAMM3R Re: sockets; table rows - 19/03/06 07:43 PM
Great. I edited this and got it to set the %var right. But where do I put the command for when it's done setting the var? When its set the var with all the table rows, i want it to echo that var. But when i put the echo command in the code it is executed for every row. Where do I put the echo command in that code to make it run only once the var is all set?
© mIRC Discussion Forums