如何在VB中调用函数名称引用字符串值的函数

Kra*_*atz 2 vb6

我有这个算法,我想在VB6上实现.

Sub Main()
dim stringVal1 as string, stringVal2 as string
dim getOne as boolean

stringVal1 = "FunctOne"
stringVal2 = "FunctTwo"

if getOne then
    'Call Function with function name assigned to stringVal1 ... how to call the function here?**
else
    'Call Function with function name assigned to stringVal1 ... how to call the function here?**
end if

End Sub


Function FunctOne()
   Msgbox "I'm function one"
End Function

Function FunctTwo()
   Msgbox "I'm function two"
End Function
Run Code Online (Sandbox Code Playgroud)

这可以在VB6中完成吗?

Kon*_*lph 10

通常,此类代码模式指向软件设计中的错误.

在极少数情况下,确实需要这样做,CallByName实现这一点.

例:

Call CallByName(Me, "NameOfFunction", vbMethod, arguments)
Run Code Online (Sandbox Code Playgroud)

  • @Andrey也许如果你非常讨厌VB6,你就不应该对VB6问题发表评论 (4认同)