我编写了一个类似于以下示例的模块:
Public Module aModule
Private Sub doSomethingRelevant()
Dim s As String = "foo"
Dim o As Object = s
aModule.performCrashyThing(s) ' Success
aModule.performCrashyThing(o) ' Error
End Sub
Private Sub performCrashyThing(s as String)
' Blah blah
End Sub
Private Sub performCrashyThing(l as Long)
' Blah blah
End Sub
End Module
第二个调用performCrashyThing(o)
引发异常:
未找到类型为“ aModule”的公共成员“ performCrashyThing”。
如果我打开此子例程Public
(不用使用Long
参数触摸第二个子例程),它不会发牢骚。我不明白,因为调用是在模块内部执行的。
答案 0 :(得分:0)
答案 1 :(得分:0)
不确定要完成传递对象的目的。这里有一些值得深思的地方。我添加了performCrashyThing的对象方法,该方法确定应调用哪个特定的performCrashyThing。
Public Module aModule
Public Sub doSomethingRelevant()
Dim s As String = "foo"
Dim o As Object = s
aModule.performCrashyThing(s)
aModule.performCrashyThing(o)
o = 1L
aModule.performCrashyThing(o)
End Sub
Private Sub performCrashyThing(obj As Object)
If TypeOf obj Is String Then
performCrashyThing(DirectCast(obj, String))
ElseIf TypeOf obj Is Long Then
performCrashyThing(DirectCast(obj, Long))
Else
Stop
End If
End Sub
Private Sub performCrashyThing(s As String)
' Blah blah
End Sub
Private Sub performCrashyThing(l As Long)
' Blah blah
End Sub
End Module