Hi all,

I'm about to get a little long winded here and I'm sorry for that but I have a couple of issues that I need guidance with.

I have assembled a procedure that basically performs a bunch of web browser clicks to query Statistics Canada (SC). The query itself is intensive on SC’s server as I will receive SC server side errors and fail the procedure. Sometimes there are no issues so I know that the SC server can handle the query. When the procedure is successful, it downloads a csv file that is only 7kb.

I also get browser errors regarding javascript and I don’t know how to handle that within the confines of VB.NET’s WebBrowser. As it is, I have to manually stop it from running or don’t, it doesn’t matter with regards to the query but it does stop my code at the DocumentCompleted event.

My questions are:
What is my best course of action for querying the SC website? I have a couple of thoughts but don’t know how to implement either so I’ll just put them out there.

Option 1: Query the website when demand is low on the server. For example, having the procedure run at say 3:00 am Central (guessing at the time) may work but I am unsure. If this is a good option, I have no clue regarding how to time when the procedure should start.

Option 2: Cut my query into 4 queries that run sequentially. For instance, in my procedure right now, I load a string type variable with comma separated values that I coded to be extracted from our database. If I could cut this string into say 4 strings and then somehow have my procedure repeat itself and start the query all over again (4 times), I could see it working.

Is there an Option 3?
As it is, I think Option 1 is more ideal but as I said, I don’t have a clue regarding how I can set the time to run.

My final question is how do I deal with the javascript errors so that I can run this procedure when there is no one around?

This may help with the script errors issue. Set the "ScriptErrorsSuppressed" property on the WebBrowser control to True. That will prevent the error dialog from opening.

Hi TnTinMN, do I have to set the property back to false at the end of the procedure or do I just leave the property as true. I know that with VBA, I would have to set properties back to their original settings so that Excel would work properly but I am unsure with regards to using VB.NET.

I am not aware of any issues in setting this property. I suspect that any issues you had in Excel VBA may have involved a registry value getting changed when you set a property, but that's just a guess. I normally enable script error suppression at the design level.

As these are errors are typically generated by bad java script code, thus supressing them should not be an issue. However, this little tidbit from MS makes me wonder.

When ScriptErrorsSuppressed is set to true, the WebBrowser control hides all its dialog boxes that originate from the underlying ActiveX control, not just script errors. Occasionally you might need to suppress script errors while displaying dialog boxes such as those used for browser security settings and user login. In this case, set ScriptErrorsSuppressed to false and suppress script errors in a handler for the HtmlWindow.Error event. For more information, see the code example in this topic.

See this for more info.

I also get browser errors regarding javascript and I don’t know how to handle that within the confines of VB.NET’s WebBrowser. As it is, I have to manually stop it from running or don’t, it doesn’t matter with regards to the query but it does stop my code at the DocumentCompleted event.

I don't know if you are aware of this or not, but when navigating to a given Url, you will likely get multiple "DocumentCompleted" events fired. The way to handle this is:

  Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
     If e.Url <> WebBrowser1.Url Then
        MsgBox(e.Url.ToString & " completed first")
     Else
        MsgBox(WebBrowser1.Url.ToString & " is finally completed")
     End If
  End Sub

This site (http://detectmybrowser.com/) is handy for testing a browser's capabilities. It throws errors is script error suppression is disabled.

As it is, I think Option 1 is more ideal but as I said, I don’t have a clue regarding how I can set the time to run.

The easiest way is to use Window's Task Scheduler to launch your app at the needed time. Or do you want to know how to create a alarm clock in your application that will raise an event to trigger your query?

Comments
Thank you very much

I haven't notice there being a problem with multiple document completed events but since this is intended to be automated without eyes watching it, every precaution is very important to me. I'm going to see how I can fit that If statement into my code block.

The easiest way is to use Window's Task Scheduler to launch your app at the needed time. Or do you want to know how to create a alarm clock in your application that will raise an event to trigger your query?

I think the task scheduler would probably be sufficient. I'm not sure how to use the scheduler but I'm about to find out. Thanks for all your help here, I truly appreciate it.

This question has already been answered. Start a new discussion instead.