(Mar 26, 2014 08:57 PM)DBots Wrote: You could use the .Lines property in RichTextBox.
You could then get your URL with .Lines(0), .Lines(1), etc. on every timer tick.
TextBox also have lines property 😊
Do you want it to continuously loop through the links or just once each?
(Mar 27, 2014 06:32 PM)Vipеr Wrote: Basically what I want to do is have a RichTextBox with a bunch of links, for example:
www.google.com
www.yahoo.com
When I press a button I want the WebBrowser goes to the first link which is google.com, then the second link yahoo.com but between every website it waits 5 seconds. So it would be: webbrowser navigates to google.com, waits 5sec, navigate to yahoo.com, wait 5sec...
I don't want it to loop, just goes through the list once then it stop.
Doesn't the System.Threading.Sleep(5000) stop the entire program and not just the webbrowser? That would just do the same as skipping to the last link but with a 5sec delay after the button is pushed.
Code For i As integer = 0 To RichTextBox1.Lines.Length - 1
WebBrowser1.navigate(RichTextBox1.Lines(i))
Threading.thread.sleep(5000)
Next
Msgbox("done")
Typed on my phone
(Mar 28, 2014 07:12 AM)wizardwizard Wrote: Thats what I gave.
Well thats why you should use a document completed instead of a wait. AndAlso what I gave naiivgates all of them. Are you sure you are starting the count at 0?
You gave a set number, 5. I did it so it works with any number of lines.
(Mar 28, 2014 09:12 PM)chaddiablo Wrote: Code Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
WebBrowser1.Navigate(TextBox1.Text)
End Sub
If you need additional help LMK, I've already built multiple bots like this.
PS. Don't use rich text box, if you want more lines on the text use 'ListBox' Ex:
Code Listbox1.Items.Item(0)
This will use the first line you have in the listbox
PS..PS...
Don't use thread sleep. Create a timer event.
Code Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Timer1.Start()
End Sub
Code Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
WebBrowser1.Navigate(Listbox1.Items.Item(0))
Timer2.Start()
End Sub
You get the point
Chaddiablo
i suggest you learn before trying to teach also.
(Mar 28, 2014 01:16 PM)ViperCoder Wrote: What code can I use so that the program checks to see if the website is fully loaded, then changes? Btw thanks for the heads-up about the code tags, didn't think about it.
Code Dim i As Integer = 0
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If i >= RichTextBox1.Lines.Length - 1 Then
i = 0
WebBrowser1.Navigate(RichTextBox1.Lines(i))
Else
i += 1
WebBrowser1.Navigate(RichTextBox1.Lines(i))
End If
End Sub
Typed from memory without testing, but that should continuously loop through the websites
(Mar 30, 2014 12:49 PM)ViperCoder Wrote: I tried out the code and it worked perfectly, thanks!
Code Public Class Form1
Dim i As Integer = 0
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If i >= RichTextBox1.Lines.Length - 1 Then
i = 0
WebBrowser1.Navigate(RichTextBox1.Lines(i))
Else
i += 1
WebBrowser1.Navigate(RichTextBox1.Lines(i))
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate(RichTextBox1.Text)
End Sub
End Class
Now only if you could tell me how to make it wait 5 sec between each link and have it stop after it goes through all the links. Thanks for everyone's help! 🙂
Code Public Class Form1
Dim i As Integer = 0
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If Not i >= RichTextBox1.Lines.Length - 1 Then
Threading.Thread.Sleep(5000)
i += 1
WebBrowser1.Navigate(RichTextBox1.Lines(i))
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
i = 0
WebBrowser1.Navigate(RichTextBox1.Text)
End Sub
End Class
That should work. I think. Still not tested :P
These threads are great. One more stupid idea after another. Use a Queue(Of string you bellends and the documentcompleted event. No timer or sleep ever needed.
a previous example http://www.vbforums.com/showthread.php?7...ost4631607
i do this by declaring a global boolean... set to false.
once the timer reaches 5 seconds i set the boolean to true.
then i use a while loop that exits once i have looped through all the urls. (use a variable "count" to keep track of the number of urls i have visited.)
inside the loop i have a if statement that checks if the boolean is true, (5 min have passed)
if the boolean is true, i navigate too the next site and i increment the "count" variable.
that's all u really need... keep in mind that you cant use the sleep, this will make the program non responsive and the website wont load.
Always make sure the inside your loop you state: "application.doevents;". this will allow the program to load the website even when its in the loop.
hope this helps :)
|