By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

I need help Looping Code in Visual Basic

P: 1
Hey guys, I'm a VB noob sorry.... but I am making a simple friend adder for a social networking site called Teenspot.
Right now, when i click a button it will add the username that is on the listbox and add that person. What i am trying to do is make it automatically go down the list and add all of the usernames. To do that I just need to figure out how to correctly loop this code below

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  2.  
  3.         WebBrowser1.Navigate("www.teenspot.com/profiles/" & ListBox1.SelectedItem & "/add")
  4.         ListBox1.SelectedIndex = ListBox1.SelectedIndex + 5
  5.  
  6.         ' This is the "sleep" function.
  7.         ' This makes your webbrowser finish loading before new action.
  8.  
  9.  
  10.         Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete And WebBrowser1.IsBusy = False
  11.             Application.DoEvents()
  12.         Loop
  13.  
  14.         WebBrowser1.Document.GetElementById("confirm").InvokeMember("click")
  15.  
  16.  
  17.         Try
  18.         Catch ex As Exception
  19.             ' Generates a messegebox with the error.
  20.             MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
  21.  
  22.         End Try
  23.  
  24.     End Sub
I have tried all kinds of ways to loop it but the problem i am having is that it just goes to the "add this person" page and it doesn't actually click yes to confirm the add. It skips the second part of the code. If someone could please help me that would be great.
Oct 30 '12 #1
Share this Question
Share on Google+
1 Reply


IronRazer
P: 83
Hello cheesenips,
I see what the problem is. I had the same problem in my internet radio recorder program. I am sure you have noticed that when you open a website in IE that the page loads some stuff and then stops and starts a few times before the page is finished loading. The first time your WebBrowser1 stops it tells your Do Until loop that it has finished loading. Now it moves to the next command which is to click the button before WebBrowser1 is really finished loading the page.

I am not a member of the website this is being used on so i need to know the following before i can give a good example. I need to know if after the button on the website is clicked does it redirect you to another page on the site or does it stay on the same page ? If it stays on the same page does it take a few seconds for the new name to register before you can continue ?
Jan 20 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.