programming a dialog that pops up when error occurs

razz

Well-known member
Joined
Oct 11, 2008
Messages
67
Programming Experience
Beginner
As part of a review of my program on Softpedia, the Reviewer stated the following:
If you call on a piece of software and it is not installed on your computer the application will pop up a nasty error message that may discourage beginners. Popping a dialog saying the reason of the error or that the software is not installed on the system would be a great fix.

Can anyone tell me how to accomplish this in VB 2008.

Thank you very much for your time.
 
Put this at the top of your file source:
VB.NET:
Imports System.File.IO

Then, use this code to check if a file exists. If it does, open that file. If not, give an error "File not found."

VB.NET:
If File.Exists("c:\application.exe") Then
Shell("c:\application.exe")
Else
    MessageBox.Show("File not found.")
End If

What if the file is in the same folder as the current application, but that folder could be anywhere on the computer? In that case, you would want to use this code:
VB.NET:
        Dim filedest = My.Application.Info.DirectoryPath.ToString & ".\" & "application.exe"
If File.Exists(filedest) Then
Shell(filedest)
Else
    MessageBox.Show("File not found.")
End If
 
As part of a review of my program on Softpedia, the Reviewer stated the following:
If you call on a piece of software and it is not installed on your computer the application will pop up a nasty error message that may discourage beginners. Popping a dialog saying the reason of the error or that the software is not installed on the system would be a great fix.

Can anyone tell me how to accomplish this in VB 2008.

Thank you very much for your time.
I'm willing to bet the error message the reviewer got is because they don't have the .Net Framework installed, which is beyond your control.

However, you can smooth things out a little by creating an installer (you can use the Setup & Deployment project as one way to do it) which will detect the Framework and if it isn't installed, prompt the user asking if they'd like to install it.
 
I'm willing to bet the error message the reviewer got is because they don't have the .Net Framework installed, which is beyond your control.

However, you can smooth things out a little by creating an installer (you can use the Setup & Deployment project as one way to do it) which will detect the Framework and if it isn't installed, prompt the user asking if they'd like to install it.
I do use an installer (which is freeware and I find excellent) - "Inno Setup Compiler". An initial note states the following:

In order to run the program, ".Net Framework 2.0" or higher must be installed on your computer. Any Vista operating system comes with .Net 2.0 installed. With XP
it is an optional service installed with Windows Update or other applications that require it.

If you are not sure if you have .Net Framework 2.0 on your computer, then do the following: click on Start, then Control Panel, then Add or Remove Programs.
".Net Framework 2.0" should be listed, if it is not, then you need to download and install it. To download, Copy and Paste the following URL in your browser:

Download details: .NET Framework Version 2.0 Redistributable Package (x86)
So I doubt if that was the problem that the Reviewer had. It is a fact that my program does indeed cause an error if it points to a program that is not installed on the user's PC.

Anyone who may be interested to have a look at my freeware program (A-Z Freeware Launcher) three links follow. I would greatly appreciate any comments both positive and negative and ANY advice will be greatly appreciated:

(1) From Softpedia

(2) From CNET

(3) Binary file only with Black Skin version from my website

Thank you all!
 
Put this at the top of your file source:
VB.NET:
Imports System.File.IO

Then, use this code to check if a file exists. If it does, open that file. If not, give an error "File not found."

VB.NET:
If File.Exists("c:\application.exe") Then
Shell("c:\application.exe")
Else
    MessageBox.Show("File not found.")
End If
Thank you Untamed for the excellent advice. I will work on that to incoporate this change within my next program version. This will be a great improvement to my program. Thanks again!
 
This part of my program is working perfectly now.

By the way, I had to change "Imports System.File.IO" to "Imports System.IO".
When I used the former, VB 2008 displayed an error and it would not work.

Thanks again for your help regarding this matter.
 
Back
Top