Question

In VBA There is a problem you will encounter when error checking the code. Find and...

  1. In VBA There is a problem you will encounter when error checking the code. Find and fix that error so the program works correctly and then report the answer you get when x = 1.83 when the approximate relative error reaches 0.005. Also report the number of terms it took to get to that answer.

Option Explicit

Function TaySeries(x, Error)

Dim AddSum, TotSum, n As Single

TotSum = 0

For n = 1 To 100

    AddSum = (-1) ^ (n + 1) * (1 / n) * (x - 2) ^ n

    TotSum = TotSum + AddSum

    If (AddSum / TotSum) < Error Then n = 101

Next

TaySeries = TotSum

End Function

Homework Answers

Answer #1

To clear the error we use On Error GoTo -1. Think of it like setting a mouse trap. When the trap goes off you need to set it again.

In the code below we add this line and the second error will now cause the code to jump to the eh_other label

Sub TwoErrors()

On Error Goto eh
  
' generate "Type mismatch" error
Error (13)

Done:
Exit Sub
eh:
' clear error
On Error Goto -1
  
On Error Goto eh_other
' generate "Application-defined" error
Error (1034)
Exit Sub
eh_other:
Debug.Print "eh_other " & Err.Description
End Sub

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT