VB.net... *Tearing out hair*

Discussion in 'World of SPAM' started by Fexxel, Jun 24, 2009.

  1. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    I thought this would be a simple project.
    I saw Jubixion's (forgive me if I typed your name wrong) greasemonkey script maker and I thought I'd make some minor improvements to it (random refresh rate, @author meta media)
    Well, here's the code:
    Code (Text):
    1.     Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
    2.         Timer1.Interval = (Integer.Parse(msablist.Items.Count()) + Integer.Parse(notouch.Text))
    3.         Timer2.Enabled = True
    4.         gm.Items.Add("// ==UserScript==")
    5.         gm.Items.Add("// @name           " & nameprog.Text)
    6.         gm.Items.Add("// @description    " & derip.Text)
    7.         gm.Items.Add("// @author         " & author.Text)
    8.         gm.Items.Add("// @namespace      http://www.userscripts.org/")
    9.         gm.Items.Add("// @include        http://www.neopets.com/objects.phtml?type=shop&obj_type=" & shopid.Text)
    10.         gm.Items.Add("// @include        http://www.neopets.com/objects.phtml?obj_type=" & shopid.Text & "&type=shop")
    11.         gm.Items.Add("// ==/UserScript==")
    12.         gm.Items.Add("var minRefresh = " & minref.Text & ";")
    13.         gm.Items.Add("var maxRefresh = " & maxref.Text & ";")
    14.         gm.Items.Add("var x = (maxRefresh - minRefresh)*Math.random() + minRefresh;")
    15.         gm.Items.Add("")
    16.         gm.Items.Add("if(document.body.innerHTML.indexOf('" & msablist.SelectedItem & "') > -1) {")
    17.         gm.Items.Add("var item= document.evaluate('//b[. = " & msablist.SelectedItem & "]',document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);if (item.snapshotlength > 0){item = item.snapshotItem(0);selectedlink=item.previousSibling.previousSibling;window.location = selectedlink}return;}")
    18.                 If Timer1.Enabled = True Then
    19.             If Timer1.Interval > (gm.Items.Count() + 11) * 2 Then
    20.                 msablist.SelectedItem = msablist.SelectedIndex + 1
    21.                 gm.Items.Add("else if(document.body.innerHTML.indexOf('" & msablist.SelectedItem & "') > -1) {")
    22.                 gm.Items.Add("var item= document.evaluate('//b[. = " & msablist.SelectedItem & "]',document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);if (item.snapshotlength > 0){item = item.snapshotItem(0);selectedlink=item.previousSibling.previousSibling;window.location = selectedlink}return;}")
    23.                 gm.Items.Add("")
    24.             Else
    25.                 gm.Items.Add("else { window.setTimeout(function(){window.location.reload() ;},x) ;}return;")
    26.                 Timer1.Enabled = False
    27.             End If
    28.         End If
    29.     End Sub
    unfortunately, this doesn't work.
    I am in quite the tussle for this one.
    I made a second timer, hoping it would properly trigger the first timer.
    Unfortunately, however, the output doesn't properly work.
    It doesn't "loop". It just runs once through the whole code and stops.
    Anyways, using "test" text input and using a pharmacy list (7 items) I got this as output: (I deleted the meta data)
    Code (Text):
    1. var minRefresh = testmin;
    2. var maxRefresh = testmax;
    3. var x = (maxRefresh - minRefresh)*Math.random() + minRefresh;
    4.  
    5. if(document.body.innerHTML.indexOf('Tasty Pie') > -1) {
    6. var item= document.evaluate('//b[. = Tasty Pie]',document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);if (item.snapshotlength > 0){item = item.snapshotItem(0);selectedlink=item.previousSibling.previousSibling;window.location = selectedlink}return;}
    7. else { window.setTimeout(function(){window.location.reload() ;},x) ;}return;
    8.  
    See what I mean? It doesn't loop the second part of the script...

    Oh, and to explain my coding:
    I figured the metadata takes 11 lines total. So I could have it so that the timer stops (thus the process) if the gm.listbox item count was smaller than 11 + the # of items in the list * 2 (because it takes up two lines in the listbox) so... Yep. If theres a better way (which there probably is :arf: ) then please do share.
    -Fexxel
    PS: Ricky/Tharoux/Billy to teh rescue? :arf:
     
  2. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39
    i have no clue what you are trying to do
    #1 why would you have a vb.net program to write a gm script for you?
    #2 i dont think you understand timers at all
     
  3. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    1. I am trying to improve this: downloads.php?d=226
    2. Faster, easier, simple.
    3. I edited back out the re-trigger timer.
    Anyways, it still doesn't work.
    I'm trying to make it so that it LOOPS. But it won't loop. It runs through then stops.
     
  4. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    Why would you use timers to loop when there are just enough constructs to loop without many workarounds? Look into the Do... While and For... Next loops (2nd one mostly as this will be the one you'll probably end up using)
     
  5. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    Ok, after reading ricky's post and a long MSN chat with Billy (YOU ROX BILLEH!)... It works... I think
    Gotta go test it again now.
    And ricky:
    I used timers because... I rarely ever use next.
    However, Billeh has taught me the way of "next" and I'm all good now...
    And it works! Uploading it now.