WebBrowser Help
Hi!!:
I have a little problem, I want to get all the text in the WebBrowser Control (Web) current page, I wrote:
Dim iFile1 as Integer
Dim sURL1 as String
sURL1="http://www.microsoft.com/spanish"
Web.Navigate(sURL1)
Dim text As String
text = Web.Document.innerText
iFile1 = FreeFile
Open App.Path & "\Param.txt" For Output As #iFile1
Print #iFile1, text;
Close #iFile1
But, when I Pressed F5 Error '91' appears.
Can someone tell me what's my mistake, Please!!!??
[569 byte] By [
mechis] at [2007-11-11 7:06:01]

# 1 Re: WebBrowser Help
Hi
The problem is that you are trying to save the text before the page has finished loading. I tried the following with your code, and it seems to work:
1) Put the following code where your current code is now:
Dim sURL1 As String
sURL1 = "http://www.microsoft.com/spanish"
web.Navigate (sURL1)
2) Put this code (the rest) in your webcontrol's DocumentComplete event:
Dim iFile1 As Integer
Dim text As String
DoEvents
text = web.Document.body.innerText
DoEvents
iFile1 = FreeFile
Open "c:\Param.txt" For Output As #iFile1
Print #iFile1, text;
Close #iFile1
I tried it, and it works. Let me know if you still have problems (paul@realiscape.net).
Camper Joe.
# 2 Re: WebBrowser Help
THX a lot, but I have a question, I wrote:
Public Sub ParamList()
sURL1 = "http://www.microsoft.com/spanish"
Web.Navigate (sURL1)
Web_DocumentComplete Web, sURL1
End Sub
Private Sub Web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim Text As String
DoEvents
Text = Web.Document.body.innerText
DoEvents
iFile1 = FreeFile
Open App.Path & "\Param.txt" For Output As #iFile1
Print #iFile1, Text;
Close #iFile1
End Sub
And I still have the same error
mechis at 2007-11-11 17:28:35 >

# 3 Re: WebBrowser Help
You don't call Web_DocumentComplete, it's an event procedure; it runs automatically when the document has finished loading. Enter the code exactly as Camper_Joe posted it.
# 4 Re: WebBrowser Help
I think the problem is that I have many frames in my Project.
How can I make it work?
mechis at 2007-11-11 17:30:27 >

# 5 Re: WebBrowser Help
I tried it, but I removed the following line:
Web_DocumentComplete Web, sURL1
And it worked.
Try it, then let me know
# 6 Re: WebBrowser Help
Thanks Camper Joe and Phil Weber, I really appreciate your help.
I corrected my mistakes, I ereased that line. But the program does not get the file yet, I checked the VB Documentation and I think the program does not get the file because I have many frames in my project.
Is there a way to get the file leaving the frames or I have to delete all the frames?.
THX.
mechis at 2007-11-11 17:32:38 >

# 7 Re: WebBrowser Help
When you say it doesn't get the file, what exactly do you mean?
Camper Joe.
# 8 Re: WebBrowser Help
Hi!!:
I mean that when I press F5 the program runs but it doesnt download the "Param.txt" file. I checked the VB Documentation and I think the program does not download the file because I have many frames in my project.
THX alot
mechis at 2007-11-11 17:34:33 >

# 9 Re: WebBrowser Help
Does the web page load in the viewer?
What do you mean with "frames"? Are they standard Frame controls?
Error 91 is object not set, can you post the line where this error occour?
Marco
mstraf at 2007-11-11 17:35:42 >

# 10 Re: WebBrowser Help
Yes, the web page is loaded in the viewer, and i'm using normal frames in my project
mechis at 2007-11-11 17:36:39 >

# 11 Re: WebBrowser Help
frame controls should be any problem. Where did you read that?
If you are still getting error 91, it will be really helpful for us to know where the problem is...
Did you turn Option Explicit on?
Marco
mstraf at 2007-11-11 17:37:38 >

# 12 Re: WebBrowser Help
I read it in the MSDN, I dont get Error 91 anymore, THX a lot
mechis at 2007-11-11 17:38:35 >

# 13 Re: WebBrowser Help
do you mean that now you are saving the file ok?
Marco
mstraf at 2007-11-11 17:39:42 >

# 14 Re: WebBrowser Help
No, I run the program but I can't download the file, none error appears
mechis at 2007-11-11 17:40:47 >

# 15 Re: WebBrowser Help
This code looks perfectly fine with me (I just put a webControl called "web" in a form)
Option Explicit
Private Sub Form_Load()
web.Navigate "www.microsoft.com/spanish"
End Sub
Private Sub web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim text As String
text = web.Document.body.innerText
Dim iFile1 As Integer
iFile1 = FreeFile
Open App.Path & "\Param.txt" For Output As #iFile1
Print #iFile1, text
Close #iFile1
End Sub
I suggest you to put a breakpoint at the beginning of the DocumentComplete event, and step through the code by F8. If the app never reaches the breakpoint, there is some more serious bug in your code, and in that case I suggest you to post all your code here.
Marco
mstraf at 2007-11-11 17:41:40 >
