is there a better way i could write this(using sleep)

ident
05-31-2005, 02:16 PM
the problem im having now is that i get vb to look into a pages source stored in txtSource then return what im looking for. but as the web page takes a couple of seconds to load my code has all ready cycled through so i dont get a value returned. I thought about using the sleep process to help. here is what iv got


Private Sub btnGet_Click()
On Error Resume Next

'Enable timers
Timer1.Enabled = True
Timer2.Enabled = True

Dim UserName
UserName = "http://www.squatjuice.com/cgi-bin/yabb/YaBB.pl?action=viewprofile;username=" & cboAddress.Text
If cboAddress = "" Then Exit Sub
WebBrowser1.Navigate UserName

Sleep (3000) 'Delays for 3 seconds

'contine you process

UserAvailable = IsUserOnline(txtSource)
If UserAvailable = online Then
MsgBox ("User Online")
End If
If UserAvailable = Offline Then
MsgBox ("User Offline")
End If
End Sub


the problem that im having is that the whole proces is paused for 3seconds. what i was hoping for is that it would run the first pice of code then sleep for 3seconds then continue. any suggestions???? i hope i explained this ok :D

Bolek
05-31-2005, 02:35 PM
What about this:


public sub NonBlockingSleep( byval milisec as long)
dim n as long, i as long
n = milisec/100
for i=1 to n
sleep 100
doevents
next i
end sub


This will sleep the process for 100 miliseconds, then do all events (ie. mouse clicks etc.), sleep another 100 ms etc. So it will appear to the user that it's not sleeping.

However, a better would be to read some status variable of the Webbrowser to determine if it has already finished loading.

ident
05-31-2005, 04:48 PM
i found the problem when i use

txtSource = brwsMain.Document.documentElement.innerHTML

it is only displaying half of the pages source code :confused: why??? its stopping at <head> and ignoring the <body>

Qua
05-31-2005, 05:16 PM
the problem im having now is that i get vb to look into a pages source stored in txtSource then return what im looking for. but as the web page takes a couple of seconds to load my code has all ready cycled through so i dont get a value returned. I thought about using the sleep process to help. here is what iv got


Private Sub btnGet_Click()
On Error Resume Next

'Enable timers
Timer1.Enabled = True
Timer2.Enabled = True

Dim UserName
UserName = "http://www.squatjuice.com/cgi-bin/yabb/YaBB.pl?action=viewprofile;username=" & cboAddress.Text
If cboAddress = "" Then Exit Sub
WebBrowser1.Navigate UserName

Sleep (3000) 'Delays for 3 seconds

'contine you process

UserAvailable = IsUserOnline(txtSource)
If UserAvailable = online Then
MsgBox ("User Online")
End If
If UserAvailable = Offline Then
MsgBox ("User Offline")
End If
End Sub


the problem that im having is that the whole proces is paused for 3seconds. what i was hoping for is that it would run the first pice of code then sleep for 3seconds then continue. any suggestions???? i hope i explained this ok :D

Instead of using that pause API. take a look at the Internet Explorer events. For your problem take a good look at DocumentComplete and a look at the property called .busy

IE events (http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/objects/internetexplorer.asp)

To answer you problem about you only getting stuff until the </head> try using document.body.innerhtml instead.

ident
05-31-2005, 05:30 PM
Instead of using that pause API. take a look at the Internet Explorer events. For your problem take a good look at DocumentComplete and a look at the property called .busy

IE events (http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/objects/internetexplorer.asp)

To answer you problem about you only getting stuff until the </head> try using document.body.innerhtml instead.


Private Sub tmr2_Timer()
On Error Resume Next
'Display source code
txtSource = brwsMain.Document.body.innerhtml
End Sub


gives me error 91 object varible or with block varible not set

herilane
06-01-2005, 03:18 PM
Has the document finished loading when this runs?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum