Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error trapping..?????

Status
Not open for further replies.

CDNJungler

Programmer
Jul 16, 2002
11
CA
I need to trap a division by zero error and unfortunately, my error trapping abilities are virtually non-existant !!!
I'm assuming I have to use some sort of On Error Resume Next
coding, but I'm not quite sure in how to do it. Any help on this is greatly apprieciated. Thanks, CDNJungler
 
rather than On Err why not just check the value of the denominator?

Dim iDenominator, iNumurator, result

iDenominator = 0
iNumurator = 10

If (iDenominator = 0 ) Then
result = "Error attempted division by zero"
Else
result = iNumurator / iDenominator
End If

Response.write result


 
Thank you for the answer, this will work for sure. Unfortunately, I have about 200 pages, and everypage has multiple divisions, all possible of being divided by the value zero. Is there any other way I can implement this without having to type it out an obscene amount of times!!!
 
put it in a function

something like

Function divisionCheck (numurator, denominator)
If (denominator= 0 ) Then
result = "Error attempted division by zero"
Else
result = numurator/ denominator
End If

divisionCheck = result
End Function

<%
Dim result
result = divisionCheck(10, 0)
Response.write result


%>

Hope this helps
 
my quick demo .. and be vbscript's lame error trapping, i'd suggest mit99mh has the right of it - you're going to have to make some kind of change to all those pages anyway - at least with javascript you can trap errors in a whole black of code with one catch.

<html><head><title>Test Area</title></head><body>
Test Area.
<%on error resume next
dim lng_1, lng_2, lng_3
lng_1=3
lng_2=1
lng_3=0
Response.Write lng_2/lng_1
%><br /><%
if err.number=0 then
Response.Write &quot; OK&quot;
else
Response.Write &quot; NOK&quot;
end if
%><br /><%
Response.Write lng_2/lng_3
%><br /><%
if err.number=0 then
Response.Write &quot; OK&quot;
else
Response.Write &quot; NOK&quot;
end if
%>
</body></html> codestorm
Fire bad. Tree pretty. - Buffy
Kludges are like lies.
You're not a complete programmer unless you know how to guess.
I hope I never consider myself an 'expert'.
<insert witticism here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top