Results 1 to 5 of 5

Thread: Wait???

  1. #1

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219

    Wait???

    Hi in a timer tick event a web broswer navigates to a web page but i want it to wait about 2 seconds so the page can load then continue with the code. I need to keep this all in one evrnt. Any ideas? Heres the code:

    VB Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.         web1.Navigate("http://www.22klmqu56.com/attacklist.php?c=1&uname=&page=" & page - 1 & "&jpage=" & page & "")
    3. '''''''***WAIT 2 SECONDS HERE***''''''''''
    4.         Dim ips As IPersistStreamInit
    5.         Dim iptr As IntPtr
    6.         Dim strm As UCOMIStream
    7.         ips = DirectCast(web1.Document, IPersistStreamInit)
    8.         iptr = Marshal.AllocHGlobal(2048)
    9.         CreateStreamOnHGlobal(iptr, True, strm)
    10.         ips.Save(strm, False)
    11.         GetHGlobalFromStream(strm, iptr)
    12.         Dim pattern As String = "(?<=\""\>)\w+(?=\<\/a\>\<\/TD\>\<TD\>)"
    13.         Dim reg As New System.Text.RegularExpressions.Regex(pattern)
    14.         Dim mcol As System.Text.regularexpressions.MatchCollection = reg.Matches(Marshal.PtrToStringAnsi(iptr))
    15.         For Each m As System.Text.RegularExpressions.Match In mcol
    16.             ListBox1.Items.Add(m.Value)
    17.         Next
    18.         Timer1.Enabled = False
    19.     End Sub
    -Rob

  2. #2
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    Easiest way is probably to have a private boolean which checks if it is the first or second tick.

    e.g a small slice of code. (Assume bolHadFirstTick is initialized to
    false)


    VB Code:
    1. If bolHadFirstTick = True Then
    2.             'Do stuff
    3. Else
    4.    'Set the timers interval to 2 seconds
    5.    Timer1.Interval = 2000
    6.     'Change the flag
    7.     bolHadFirstTick = True
    8. End If

    Where "Do Stuff" is your code after wait 2 seconds here.

    The timer will tick the first time, set it's interval to two seconds and flag the boolean to say it's had it's first tick. Then the clock will keep ticking until it hits the interval again, this time bolHadFirstTick will be true and the rest of your code can execute.

  3. #3

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    ok thanks for you reply, what is bolHadFirstTick? Iys gets underlined.
    -Rob

  4. #4

    Thread Starter
    Addicted Member VBGangsta's Avatar
    Join Date
    Aug 2003
    Location
    New York
    Posts
    219
    opps never mind, i forgot to set it as a boolean. Ecellent it works great!!
    Last edited by VBGangsta; Dec 2nd, 2003 at 09:16 PM.
    -Rob

  5. #5
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    You could also probably do a sleep() but if you have it working, then cool!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width