Threading.Thread.Sleep(xx) '' xx is in milliseconds. 1000 ms = 1 sec.
Maybe. ?
Someone help and old noob out im making an account creator and for numerous reasons i want the program to fill in the form slowly, so it looks more human and also for other reasons, so for example if I have code like this
It fills in everything instantly, I want a way so it maybe waits a second before filling in the next box. I have tryed the sleep function that works but freezes up the program just looks really bad. Also tryed a delay function using a module, it was a tut i found but that didn't seem to work either. Ow and btw reason im using .Focus() is because im using a small browser so it will move into view. Anyways any help would be greatly appreciated as this is something i have wanted to learn for along time.Code:WebBrowser1.Document.GetElementById("iFirstName").Focus() WebBrowser1.Document.GetElementById("iFirstName").SetAttribute("value", TextBox1.Text) WebBrowser1.Document.GetElementById("iLastName").Focus() WebBrowser1.Document.GetElementById("iLastName").SetAttribute("value", TextBox2.Text) WebBrowser1.Document.GetElementById("iBirthDay").Focus() WebBrowser1.Document.GetElementById("iBirthDay").SetAttribute("value", ComboBox2.Text) WebBrowser1.Document.GetElementById("iBirthMonth").Focus() WebBrowser1.Document.GetElementById("iBirthMonth").SetAttribute("value", ComboBox1.Text) WebBrowser1.Document.GetElementById("iBirthYear").Focus() WebBrowser1.Document.GetElementById("iBirthYear").SetAttribute("value", ComboBox3.Text)
Thanks
Last edited by silentrunner2; 04-25-2013 at 06:04 PM.
My ProjectsCOD Ghost Extreme Edition - https://www.mpgh.net/forum/723-call-d...rt-system.html
Account Creator Extreme - https://www.mpgh.net/forum/33-visual-...-websites.html
Don't Ask For Thanks Earn It
You: "Please Give Thanks"
Me: "...................No"
Threading.Thread.Sleep(xx) '' xx is in milliseconds. 1000 ms = 1 sec.
Maybe. ?
'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
--
Maybe try a chain of timers with the Interval set at 1000
eg
Code:Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick WebBrowser1.Document.GetElementById("iFirstName").Focus() WebBrowser1.Document.GetElementById("iFirstName").SetAttribute("value", TextBox1.Text) Timer2.Enabled = True Timer1.Enabled = False End SubCode:Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick WebBrowser1.Document.GetElementById("iLastName").Focus() WebBrowser1.Document.GetElementById("iLastName").SetAttribute("value", TextBox2.Text) Timer3.Enabled = True Timer2.Enabled = False End Sub
Last edited by rabbit.coder; 04-25-2013 at 10:03 PM. Reason: missing bits
Private Declare Function GetTickCount Lib "kernel32" () As Long
Sub Wait(ByVal cTime As Long)
Dim sTime As Long
sTime = GetTickCount + cTime
Do While sTime >= GetTickCount
Application.DoEvents()
Loop
End Sub
-Trying to keep it similar to your original / add as little new code as possible
or even,Code:Dim aRandomNumber As New Random() '' Used to generate random numbers (pseudo-random..) WebBrowser1.Document.GetElementById("iFirstName").Focus() WebBrowser1.Document.GetElementById("iFirstName").SetAttribute("value", TextBox1.Text) Threading.Thread.Sleep(aRandomNumber.GetNext(1000,2000)) ''Get a random number between 1000 and 2000 (1 to 2 seconds) WebBrowser1.Document.GetElementById("iLastName").Focus() WebBrowser1.Document.GetElementById("iLastName").SetAttribute("value", TextBox2.Text) Threading.Thread.Sleep(aRandomNumber.GetNext(1000,2000)) WebBrowser1.Document.GetElementById("iBirthDay").Focus() WebBrowser1.Document.GetElementById("iBirthDay").SetAttribute("value", ComboBox2.Text) Threading.Thread.Sleep(aRandomNumber.GetNext(1000,2000)) WebBrowser1.Document.GetElementById("iBirthMonth").Focus() WebBrowser1.Document.GetElementById("iBirthMonth").SetAttribute("value", ComboBox1.Text) Threading.Thread.Sleep(aRandomNumber.GetNext(1000,2000)) WebBrowser1.Document.GetElementById("iBirthYear").Focus() WebBrowser1.Document.GetElementById("iBirthYear").SetAttribute("value", ComboBox3.Text) Threading.Thread.Sleep(aRandomNumber.GetNext(1000,2000)) 'maybe not needed here. ?
-I think*, because this is going through a web-browser...generally there is nothing keeping track of "how fast" you type something in / how fast you switch between fields. With that being said..why not : )Code:Dim aRandomNumber As New Random() '' Used to generate random numbers (pseudo-random..) Dim minSleepTime as Int32 = 1000 '' in milliseconds, should be a const Dim maxSleepTime as Int32 = 2000 '' in milliseconds, should be a const WebBrowser1.Document.GetElementById("iFirstName").Focus() WebBrowser1.Document.GetElementById("iFirstName").SetAttribute("value", TextBox1.Text) Threading.Thread.Sleep(aRandomNumber.GetNext(minSleepTime ,maxSleepTime)) ''Get a random number between min and max WebBrowser1.Document.GetElementById("iLastName").Focus() WebBrowser1.Document.GetElementById("iLastName").SetAttribute("value", TextBox2.Text) Threading.Thread.Sleep(aRandomNumber.GetNext(minSleepTime ,maxSleepTime)) WebBrowser1.Document.GetElementById("iBirthDay").Focus() WebBrowser1.Document.GetElementById("iBirthDay").SetAttribute("value", ComboBox2.Text) Threading.Thread.Sleep(aRandomNumber.GetNext(minSleepTime ,maxSleepTime)) WebBrowser1.Document.GetElementById("iBirthMonth").Focus() WebBrowser1.Document.GetElementById("iBirthMonth").SetAttribute("value", ComboBox1.Text) Threading.Thread.Sleep(aRandomNumber.GetNext(minSleepTime ,maxSleepTime)) WebBrowser1.Document.GetElementById("iBirthYear").Focus() WebBrowser1.Document.GetElementById("iBirthYear").SetAttribute("value", ComboBox3.Text) Threading.Thread.Sleep(aRandomNumber.GetNext(minSleepTime ,maxSleepTime)) 'maybe not needed here. ?
Last edited by abuckau907; 04-25-2013 at 11:09 PM. Reason: missing closing paren.
'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
--
Hi thanks for your input, im not sure if im executing this wrong but it seems to loop my code over and over so it doesn't stop running?
The sleep method works but for me but it freezes up the whole program so I can't see whats going on. I was also looking around a found this method but that seems to mess with the browser and freeze it.
My ProjectsCOD Ghost Extreme Edition - https://www.mpgh.net/forum/723-call-d...rt-system.html
Account Creator Extreme - https://www.mpgh.net/forum/33-visual-...-websites.html
Don't Ask For Thanks Earn It
You: "Please Give Thanks"
Me: "...................No"
Wow sorry, somehow I totally missed the part about you already trying .Sleep() and not liking the 'gui freeze.'
I guess the easiest way (without having to explain a whole lot) would be to do as pootuba said and making a custon wait function: the key part is calling Application.DoEvents()
..from post above..
the parameter cTime is the number of "ticks" to wait, a tick being some very small fraction of a second. (idk off top of my head..) This is probably the easiest way. Replace all of the System.Threading.Sleep() calls with a call to the above Sub.Code:Sub Wait(ByVal cTime As Long) Dim sTime As Long sTime = GetTickCount + cTime Do While sTime >= GetTickCount Application.DoEvents() Loop End Sub
'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
--
Hey thanks for coming back to me, I used that code it seemed to work alittle better but once it finished it seemed to make my code run over and over i tryed removing the loop but had the same problem. Im i doing something really stupid, i used the function and then called it between codes like so "wait(10)"
Btw im running the code in a timer could not cause a problem, after it completes the timer is turned off could this maybe be conflicting with it somehow.
Thanks
Last edited by silentrunner2; 04-26-2013 at 05:18 AM.
My ProjectsCOD Ghost Extreme Edition - https://www.mpgh.net/forum/723-call-d...rt-system.html
Account Creator Extreme - https://www.mpgh.net/forum/33-visual-...-websites.html
Don't Ask For Thanks Earn It
You: "Please Give Thanks"
Me: "...................No"
abuckau907 method will work, you just need to run the code in another thread so it doesnt freeze your app.
Call it from whatever method you wantCode:Sub RunCode() 'Code here End Sub
Code:Dim T As System.Threading.Thread = New System.Threading.Thread(AddressOf RunCode) T.Start()
Just seems to freeze up the browser :/
My ProjectsCOD Ghost Extreme Edition - https://www.mpgh.net/forum/723-call-d...rt-system.html
Account Creator Extreme - https://www.mpgh.net/forum/33-visual-...-websites.html
Don't Ask For Thanks Earn It
You: "Please Give Thanks"
Me: "...................No"
@silentrunner2 plz post any code you feel is relevant. Timers shouldn't be needed, but of course *could* work. Post the code and we'll see.
- when you tried pingos threaded method, did you replace " 'code here " with all the webbrowser1 related code : you didn't leave it a blank sub, right? Silly question, but it's been known to happen.
'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
--
I didn't quite understand Pingos methods I gave it a try it ran without errors but didn't seem to work. Here is what i have at the moment it might give you a better idea of what im trying to achieve and thanks for being patient with me my knowledge is pretty basic, as you will see I don't have any code you guys recommended at the moment I removed it so I could carry on without a delay for now.
Code:Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click WebBrowser1.Navigate("https://login.live.com") TabControl1.SelectTab(1) End Sub Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted If WebBrowser1.DocumentTitle = "Sign in to your Microsoft account" And WebBrowser1.Url.ToString.StartsWith("https://login.live.com/") Then Hotmail.Enabled = True End If If WebBrowser1.DocumentTitle = "Sign up - Microsoft account" Then Hotmail2.Enabled = True End If If WebBrowser1.DocumentTitle.ToString.StartsWith("Outlook - " + TextBox3.Text) Then MsgBox("Your account has been successfully created and the details saved in the history tab") End If End Sub Private Sub Hotmail_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hotmail.Tick WebBrowser1.Document.GetElementById("idA_SignUp").Focus() WebBrowser1.Document.GetElementById("idA_SignUp").InvokeMember("click") Hotmail.Enabled = False End Sub Private Sub Hotmail2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hotmail2.Tick Try WebBrowser1.Document.GetElementById("iFirstName").Focus() WebBrowser1.Document.GetElementById("iFirstName").SetAttribute("value", TextBox1.Text) WebBrowser1.Document.GetElementById("iLastName").Focus() WebBrowser1.Document.GetElementById("iLastName").SetAttribute("value", TextBox2.Text) WebBrowser1.Document.GetElementById("iBirthDay").Focus() WebBrowser1.Document.GetElementById("iBirthDay").SetAttribute("value", ComboBox2.Text) WebBrowser1.Document.GetElementById("iBirthMonth").Focus() WebBrowser1.Document.GetElementById("iBirthMonth").SetAttribute("value", ComboBox1.Text) WebBrowser1.Document.GetElementById("iBirthYear").Focus() WebBrowser1.Document.GetElementById("iBirthYear").SetAttribute("value", ComboBox3.Text) WebBrowser1.Document.GetElementById("imembernameeasi").Focus() WebBrowser1.Document.GetElementById("imembernameeasi").SetAttribute("value", TextBox3.Text) WebBrowser1.Document.GetElementById("iPwd").Focus() WebBrowser1.Document.GetElementById("iPwd").SetAttribute("value", TextBox4.Text) WebBrowser1.Document.GetElementById("iRetypePwd").Focus() WebBrowser1.Document.GetElementById("iRetypePwd").SetAttribute("value", TextBox4.Text) WebBrowser1.Document.GetElementById("iPhone").Focus() WebBrowser1.Document.GetElementById("iPhone").SetAttribute("value", TextBox5.Text) WebBrowser1.Document.GetElementById("iAltEmail").Focus() WebBrowser1.Document.GetElementById("iAltEmail").SetAttribute("value", TextBox6.Text) WebBrowser1.Document.GetElementById("iZipCode").Focus() WebBrowser1.Document.GetElementById("iZipCode").SetAttribute("value", TextBox7.Text) WebBrowser1.Document.GetElementById("iBirthYear").Focus() SendKeys.Send("{TAB}") SendKeys.Send("{DOWN}") Hotmail2.Enabled = False MsgBox("Filling in the form has comepleted, please scroll to the bottom of the page and comeplete the captcha") WebBrowser1.Document.GetElementById("iBirthYear").Focus() SendKeys.Send("{TAB}") SendKeys.Send("{DOWN}") Hotmail2.Enabled = False Catch ex As Exception Hotmail2.Enabled = False MsgBox("something went wrong the form was unable to be comepleted") Hotmail2.Enabled = False End Try End Sub
My ProjectsCOD Ghost Extreme Edition - https://www.mpgh.net/forum/723-call-d...rt-system.html
Account Creator Extreme - https://www.mpgh.net/forum/33-visual-...-websites.html
Don't Ask For Thanks Earn It
You: "Please Give Thanks"
Me: "...................No"
Another thing to note, if you're creating a thread dont do it within the timer.
Remove the timer since you dont really need it unless you use it for something else.
Your GUI will not freeze up if you run the code in another thread.
If you run the code in the main thread, of course the GUI will freeze since you're telling the main thread to sleep for x amount of time.
Code:private declare sub sleep lib "kernel32" (byval dwMilliseconds as long) sleep(1000)
Last edited by Biesi; 04-26-2013 at 07:38 AM.
My ProjectsCOD Ghost Extreme Edition - https://www.mpgh.net/forum/723-call-d...rt-system.html
Account Creator Extreme - https://www.mpgh.net/forum/33-visual-...-websites.html
Don't Ask For Thanks Earn It
You: "Please Give Thanks"
Me: "...................No"