MedVision ad

Major Software Assignment Error traping (1 Viewer)

hr

New Member
Joined
Jun 17, 2004
Messages
7
Location
Grafton
Hi all,

Umm i am currently doing my major assignment, which is a maths program. Anyway ive basically finished the assignment and ive just realised i dont know anything about how to trap errors and such. For instance the user enters a letter instead of a number into a field for the radius for a circle and the program dies. The program is in visual basic 6 and the error code is 13 if that helps. Can anyone help or give me a site that will help.

Any help would be appreciated.

Thanks
 
Last edited:

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Use the IsNumeric function to check that the input is numeric.
 

hornetfig

Member
Joined
Jun 27, 2004
Messages
65
Location
Sydney. oddly
Gender
Male
HSC
2003
and copeous On Error Goto or On Error Resume Next statements will ensure even if there is a data error, the program doesn't fall over and dump you back to the IDE in the middle of your presentation...
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
If you're doing this in java or .NET you can make use of the Try Catch statements. However if you're in VB6 as hornetfig mentioned an On Error Goto is the method of exception handling, btw error trapping in programming terms is called "Exception Handling" there's generally two forms of exceptions, you can catch an exception or throw an exception.

for VB6

for example this code


On Error GoTo divideByErrorHandler

txtBox.text = 1/0

Exit Sub

divideByErrorHandler:

MsgBox "A divide by zero error has occured, please input a correct denominator other than zero.",vbCritical + vbOKOnly, "Division Error"

If you want to read more about it check this out:

http://msdn.microsoft.com/library/d...vbcn7/html/vaconerrorhandlingusingonerror.asp
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top