Code to Launch, Navigate, and Check for Errors
Provided by: Dan Haught, FMS Executive Vice President
Using Visual Basic .NET, you can use Start method of the
System.Diagnostics.Process class to launch an external program.
Additionally, you can use the new Try/Catch syntax to check for errors. The
following code sample, from our
Total .NET SourceBook product,
shows how to do this.
Public
Sub LaunchURLWithChecks()
' Launch the currently installed web browser, sent
' it to a specified page,
and check the status.
'
Dim MyURL As
String = "http://www.fmsinc.com"
' Use the Try keyword to set up exception (i.e. error) handling
Try
'
To do this, we use start a new process and pass it the URL.
System.Diagnostics.Process.Start(MyURL)
'
If an execption occurs, the Catch block will run
Catch
noBrowser As
System.ComponentModel.Win32Exception _
When noBrowser.ErrorCode
= -2147467259
MessageBox.Show(noBrowser.Message)
Catch other
As
System.ComponentModel.Win32Exception
MessageBox.Show(other.Message)
End
Try
End
Sub
Return to the tips page
|