I have many calls to different functions that may sometimes provoke errors. In a case of an error, I want them to return a default value. This is possible in the following "spaghetti code" example:
Sub MainTest()
a = 1
b = 0
On Error GoTo DivisionErrorHandler
c = a / b
On Error GoTo 0
MsgBox c
On Error GoTo FontNameErrorHandler
d = He.FontName
On Error GoTo 0
MsgBox d
Exit Sub
DivisionErrorHandler:
c = 0
Resume Next
FontNameErrorHandler:
d = ""
Resume Next
End Sub
Instead of this spaghetti code, I would like to write something like this:
Sub MainTest()
a = 1
b = 0
c = DefaultValue(a / b, 0)
MsgBox c
d = DefaultValue(He.FontName, "")
MsgBox d
End Sub
Is it possible? If yes, how?
Sub MainTest()
a = 1
b = 0
On Error GoTo DivisionErrorHandler
c = a / b
On Error GoTo 0
MsgBox c
On Error GoTo FontNameErrorHandler
d = He.FontName
On Error GoTo 0
MsgBox d
Exit Sub
DivisionErrorHandler:
c = 0
Resume Next
FontNameErrorHandler:
d = ""
Resume Next
End Sub
Instead of this spaghetti code, I would like to write something like this:
Sub MainTest()
a = 1
b = 0
c = DefaultValue(a / b, 0)
MsgBox c
d = DefaultValue(He.FontName, "")
MsgBox d
End Sub
Is it possible? If yes, how?