Private Sub cmdCalcSqrt_Click()
Dim dOutput As Double
lblResult = ""
dOutput = Sqrt(txtInput)
If dOutput > 0 Then
lblResult.Caption = "{" & dOutput & ", -" & dOutput & "}"
Else
Dim sErrPrompt As String 'Dim sErrPrompt <-- Corrected at Errata 2
sErrPrompt = "Error: Could not calculate root. " & vbCrLf & _
"Check your input."
ShowErrorMsg (sErrPrompt)
End If
End Sub
Private Function Sqrt(vRadicand As Variant) As Double
On Error GoTo ErrHandler:
Dim dBase As Double
dBase = CDbl(vRadicand)
Sqrt = dBase ^ (1 / 2)
Exit Function '<-- Corrected at Errata 3
ErrHandler:
If Err.Number > 0 Then
Dim sErrPrompt As String 'Dim sErr As String <-- Corrected at Errata 1
sErrPrompt = "Error No. " & Err.Number & " @ Function SquareRoot." & vbCrLf & _
"Description: " & Err.Description
ShowErrorMsg (sErrPrompt)
End If
End Function
Private Sub ShowErrorMsg(sErrPrompt As String)
MsgBox sErrPrompt, vbExclamation, "Error!"
End Sub