spiderman0009
Technical User
Can someone explain the part below that I have put in ""..
Why is it 11 and -1 I don't understand?? New to learning programming.. Thank you
Error trapping example
One short example shows you how to put VBScript error-checking to work. In the following code, the AmountPerMonth function calculaates how much money you have to save per nomth to reach a goal to purchase an item You pass the amount of the item and the number of months you're willing to wait, and it returns the amouny of the item and the number of months you're willing to wait, and it returns the amount per month you have to put back. It doesn't take into account any interest on your money, so the process is very simple.
<% DIm Amt
Amt = AmountPerMonth(1000, 0)
%>
<%=Amt%>
<% Function AmountPerMonth(Amount, Months)
On Error Resume Next
Dim MonthlyAmount
MonthlyAmount = Amount / Months
"If Err.Number = 11 Then
AmountPerMonth = -1"
Else
AmountPerMonth = MonthlyAmount
End If
End Function
%>
Computer always croak when you try to divide by zero. It can't be done. But you don't want to show the user an ugly error message. AmountPerMonth uses the On Error Resume Next to stop VBScript fron croaking an then immediately checks for the error after the calculation. A returned value of -1 indicates tat an error occurred because of bad data sent to it.
Why is it 11 and -1 I don't understand?? New to learning programming.. Thank you
Error trapping example
One short example shows you how to put VBScript error-checking to work. In the following code, the AmountPerMonth function calculaates how much money you have to save per nomth to reach a goal to purchase an item You pass the amount of the item and the number of months you're willing to wait, and it returns the amouny of the item and the number of months you're willing to wait, and it returns the amount per month you have to put back. It doesn't take into account any interest on your money, so the process is very simple.
<% DIm Amt
Amt = AmountPerMonth(1000, 0)
%>
<%=Amt%>
<% Function AmountPerMonth(Amount, Months)
On Error Resume Next
Dim MonthlyAmount
MonthlyAmount = Amount / Months
"If Err.Number = 11 Then
AmountPerMonth = -1"
Else
AmountPerMonth = MonthlyAmount
End If
End Function
%>
Computer always croak when you try to divide by zero. It can't be done. But you don't want to show the user an ugly error message. AmountPerMonth uses the On Error Resume Next to stop VBScript fron croaking an then immediately checks for the error after the calculation. A returned value of -1 indicates tat an error occurred because of bad data sent to it.