|
-
Jul 16th, 2003, 10:18 AM
#1
Thread Starter
Lively Member
-
Jul 17th, 2003, 03:37 AM
#2
Thread Starter
Lively Member
Ive tried this: (brweb = webbrowser)
VB Code:
While brWeb.ReadyState <> SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
Sleep(4000) ' Wait 4 seconds.
End While
But it is always readystate_loading.
Ive tried:
VB Code:
Dim Thread1 As New System.Threading.Thread(AddressOf loadURLSource)
Thread1.Start()
Thread1.Join()
'the rest of the subs
and tried to understand what is happening, but it just fires the commands in loadURLSource and then carries on.
Why wont it wait til the webpage and source has loaded?
Last edited by CJN; Jul 17th, 2003 at 05:06 AM.
-
Jul 17th, 2003, 04:50 AM
#3
Addicted Member
This is a very basic idea, you could download the page to a text file and check for the last tag i.e. '</html>', until you find a proper solution.
Just a thought.
Wind and waves resolves all problems.
-
Jul 17th, 2003, 05:04 AM
#4
Thread Starter
Lively Member
Thanks for your help.
I am displaying the source html in a textbox and checking to see if it has been filled. I think thats similar to the idea you suggested. The problem seems to be that anything that I do after calling the sub to download the webpage and source, for example check that the textbox is filled with the source code or start my next sub or do all that waiting stuff above stops my program bothering downloading the webpage and so it never downloads.
I know that if I remove everything after calling the sub to download the webpage and source then the webpage and source is downloaded and displayed in the webbrowser and textbox, because the program has nothing else to do but download webpage/source.
In effect I need to recreate the fact that the program thinks it has nothing else to do but download the webpage/source until it has done that and then make it carry on with the rest of my subs.
Hope you guys understand and have some ideas
-
Jul 17th, 2003, 05:13 AM
#5
np cjn , right , are you calling the "other subs" from your Document_Complete sub ?
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jul 17th, 2003, 05:27 AM
#6
Thread Starter
Lively Member
Hi,
No i'm not doing that. It goes a little something like this:
VB Code:
Private Sub MAINSUB()
'Do some other stuff, including starting a loop
'Call load web/source
loadURLSource()
'Call next lot of subs
subC()
subD() 'etc
'do some other stuff and go back to loop start
End SUb
Private Sub loadURLSource()
'Load the url and the matching html source code
'Load the url to the webbrowser control brWeb...
brWeb.Navigate(curURL)
' While brWeb.ReadyState <> SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
' Sleep(4000) ' Wait 4 seconds.
' End While
'Auto Call to the webbrowsers docComplete sub (through the doc) to load the source html when the url has finished...
End Sub
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub doc_DownloadComplete() Handles doc.DownloadComplete
'Load the source html...
txtSource.Text = brWeb.Document.documentelement.outerhtml
' While loadcompl <> True
' If txtSource.Text = "" Then
' Sleep(4000) ' Wait 4 seconds.
' Else
' loadcompl = True
' End If
' End While
MsgBox("doc")
End Sub
Do you think ur idea would work, if its the only way then I will do it but putting all the rest of my subs and stuff in there is a but ugly and annoying. Cheers for the suggestion though. (you're almost becoming my VB gardian angel )
-
Jul 17th, 2003, 05:49 AM
#7
could you not do something like this :
VB Code:
Private Sub doc_DownloadComplete() Handles doc.DownloadComplete
Try
Dim htm As String = brWeb.Document.documentelement.outerhtml
MessageBox.Show(htm)
Finally
'/// call subC() & subD()
End Try
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jul 17th, 2003, 10:46 AM
#8
Thread Starter
Lively Member
-
Jul 17th, 2003, 11:19 AM
#9
Thread Starter
Lively Member
Ohhhhhhhhhhhhhhhhhhhh!!!
Thinking about it and doing a few tests, I'm afraid as good as your idea was its not going to work for me. I have to have my subs and other stuff where they started off (not in the download complete section) in order for other parts of my program to work. Darn, there must be some way of allowing it to pause while the webpage is loading and then carrying on, there just must , please let there be
-
Jul 17th, 2003, 12:22 PM
#10
what are you building? does the html have to arrive before an event triggers?
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jul 17th, 2003, 02:15 PM
#11
Thread Starter
Lively Member
Hi,
Thanks with all assistance so far...
What I am trying to do is something like the following:
1) Start loop A running through a db looking for particular URLs
2) Start loop B looking at particular things in URL
3) Load webpage X (URL taken from db)
4) Get source of X and put in txtbox
5) Read some of Source X and put in record in database
6) Read part of record and collate with other info
7) Put all this in a lstvw, do some totalling and put in txtboxes
8) Go back to 2) and find next particular thing (repeat til all things found)
9) Go back to 1) look for Webpage Y, (repeat until webpage N)
10) Display the lstvw and txtboxes to user.
The problem is mainly my loops (starting at 1 through to 9 and 2 to 8). I can put steps 5) and 6) and possibly 7) in the download_complete sub but 8) and 9) are the "next" bits of a "for loop" these cannot go in the download_complete and not having them there yet having 5, 6, 7 there means the program seems to run something like the following:
Steps..
1>2>3>8>9>10>4>5>6>7 (probably not quite that but definitely wrong anyway). I know it definitely calls 10 before the webpage/source is displayed in their webbrowser/textbox because a messagebox is displayed found in sub 10 and the webpage hasn't even been displayed????
-
Jul 18th, 2003, 04:39 AM
#12
right , well firstly i wouldn't use a webbrowser to get the html , System.Net.WebClient is built for that .
you could do it all within 1 sub if you want to read through an access db and get the url's sources that corrispond with those url's in the db , to get the source you use WebClient and StreamReader ( i always use this method , it's really fast compared to a browser )
here's an example that might inspire you :
VB Code:
Imports System.Net
' /// ^^^ top of form's code page ...
'/////////////////////////////////////////////
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strUrls() As String = {"http://google.com", "http://www.vbforums.com"}
Dim webservice As New WebClient()
Dim x As Integer
For x = LBound(strUrls) To UBound(strUrls)
Dim s As IO.StreamReader = New IO.StreamReader(webservice.OpenRead(strUrls(x)))
MsgBox(s.ReadToEnd) ' /// lets see the source code.
s.DiscardBufferedData()
s.Close()
s = Nothing
Next
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jul 18th, 2003, 08:11 AM
#13
Thread Starter
Lively Member
Well thankyou dynamic_sysop, you have been very helpful. You suggestion may well become very useful to me in the future, because for now I have to stick with the webbrowser for reason that would take too long to explain, but I do indeed hope to get rid of it once some other issuses are sorted (making for a faster program, like you say). In the meantime I have a solution that seems to work. It is to put "Application.DoEvents" in a loop that checks if the ready state of the webbrowser has finished loading and hey presto loaded webpages and results
Cheers for all your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|