删除Return
语句!
在 VBA 中,您使用行设置返回值myEquals = ...
。
总而言之,您可以将函数简化为以下代码:
Public Function myEquals(v As CCtypestore) As Boolean
If Not v Is Nothing Then
myEquals = (Me.Acronym = v.Acronym)
End If
End Function
或者,使用这个:
Public Function myEquals(v As CCtypestore) As Boolean
On Error Goto ErrorHandler
myEquals = (Me.Acronym = v.Acronym)
Exit Function
ErrorHandler:
myEquals = False
End Function
Return
如果您想在代码中使用直接跳转,即构建意大利面条代码,这是一个古老的遗物!请参阅帮助文件中的此示例:
Sub GosubDemo()
Dim Num
' Solicit a number from the user.
Num = InputBox("Enter a positive number to be divided by 2.")
' Only use routine if user enters a positive number.
If Num > 0 Then GoSub MyRoutine
Debug.Print Num
Exit Sub ' Use Exit to prevent an error.
MyRoutine:
Num = Num/2 ' Perform the division.
Return ' Return control to statement.
End Sub ' following the GoSub statement.