Основы офисного программирования и язык VBA


Пример 10.3


Public Sub TestFact2()

Dim Msg As String

Dim VictoryCount As Integer, Prize As Long

On Error GoTo ErrHandler1

VictoryCount = 5

Prize = Fact2(VictoryCount) * 5

Debug.Print VictoryCount, Prize

VictoryCount = 10

Prize = Fact2(VictoryCount) * 5

Debug.Print VictoryCount, Prize

Exit Sub

ErrHandler1:

Msg = "Ошибка # " & Err.Number & " возникла в " & Err.Source _

& vbCrLf & " Описание: " & Err.Description _

& vbCrLf & " HelpFile: " & Err.HelpFile _

& vbCrLf & " HelpContext: " & Err.HelpContext

MsgBox Msg, vbMsgBoxHelpButton, "Error", Err.HelpFile, Err.HelpContext

'Грубое устранение причин ошибки

Err.Clear

If VictoryCount < 0 Then VictoryCount = 0

If VictoryCount > 7 Then VictoryCount = 7

Resume

End Sub




Начало  Назад  Вперед



Книжный магазин