This code look slike it would be very useful to me, with just one problem:
When I attempt to use that exact code or any derivation, I get this error:
A first chance exception of type 'System.AccessViolationException' occurred in mscorlib.dll
And when I look at the error message, it tells me that memory could be corrupt elsewhere. I've attempted this line of code by omitting the "http://" portion of the URL, by trying numerous web sites, and with various other arguments in the 2nd parameter, such as "", ControlChars.NullChar and "null". I've also reset my PC and created a brand new application with only that code and get the same results.
I am using VS.NET 2005 w/ .NET framework 2.0
I don't know if it will help, but the details from the exception object are as follows:
System.AccessViolationException was caught
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32 aWrapperTypes, MessageData& msgData)
at mshtml.HTMLDocumentClass.createDocumentFromUrl(String bstrUrl, String bstrOptions)
at MSHTML_DOM_Practice_1.Form1.createDoc(String URL) in D:\Dev V.2\Misc practice projects\MSHTML DOM Practice 1\MSHTML DOM Practice 1\Form1.vb:line 19
I'm reaching my threshold of frustration and could really use some help!
fix for accessviolation issue
Posted by sampaths85
on 04/26/2012 03:21am
This worked for me!
Just what I was looking for. Now I just need to know how to select and activate a button on the page. I'm not sure of the proper lingo becuase I'm new to any type of web development. The page that I'm opening is on an intranet and displays current data. To see the previous weeks data I have to click a back arrow labled "prior week". How do I do that in code?
Dim objMSHTML As New MSHTML.HTMLDocument
Dim objDocument As MSHTML.HTMLDocument
Set objDocument = objMSHTML.createDocumentFromUrl(txtURL.Text, vbNullString)
If you want to pass objDocument between functions then objMSHTML must be global in the module; so if you use this in a form initialise objMSHTML in Form_Load and dispose of it in Form_Terminate.
If you used that code in a function then returned the HTMLDocument you opened, the data would be lost - even though the reference passes OK.
memory leaks can you show an exaple of form_terminate?
Posted by blackbookcoder
on 10/23/2004 12:40am
memory leaks when i run this. Can you tell us how to use the Form_Terminate sub for this code?
response to memory leak question
Posted by art
on 01/20/2017 07:23am
Simply set the three objects to Nothing in Form_Unload like this:
If Not objLink is Nothing Then Set objLink = Nothing
If Not objMSHTML is Nothing Then Set objMSHTML = Nothing
If Not objDocument is Nothing Then Set objDocument = Nothing