如何在visual basic中创建具有可变数量参数的函数?恩.
x = Sum(1,2,3)
y = Sum(1,2)
Function Sum('how to declare argument here')
'Is there any special argument manipulation inside function before it is usable?
End Function
Run Code Online (Sandbox Code Playgroud) 我正在研究一个辅助宏,它调查活动excel工作簿上给定模块名称的list函数.例如:我有一个模块名称"Module1".该模块内部具有以下功能或子功能
Sub Sub1()
End Sub
Sub Sub2()
End Sub
Function Func1()
End Function
Function Func2()
End Function
Run Code Online (Sandbox Code Playgroud)
是否有可以返回函数和子名称列表的命令或例程?
使用CallByName调用classModule中的函数很容易.标准模块中的函数怎么样?
''#inside class module
''#classModule name: clsExample
Function classFunc1()
MsgBox "I'm class module 1"
End Function
''#
''#inside standard module
''#Module name: module1
Function Func1()
MsgBox "I'm standard module 1"
End Function
''#
''# The main sub
Sub Main()
''# to call function inside class module
dim clsObj as New clsExample
Call CallByName(clsObj,"ClassFunc1")
''# here's the question... how to call a function inside a standard module
''# how to declare the object "stdObj" in reference to module1?
Call CallByName(stdObj,"Func1") ''# …Run Code Online (Sandbox Code Playgroud) 我想创建一个对象...说一个"电影"对象.该对象应该有一个方法名称"停止",所以我可以在下面有这个代码
dim Mov as new Movie
Mov.Stop ' To execute the Stop method.
Run Code Online (Sandbox Code Playgroud)
在我的电影课上,我应该有这样的东西.
Sub Stop()
'code here needed for the Stop subroutine
End Sub
Run Code Online (Sandbox Code Playgroud)
但是,我不能使用"停止"作为名称,因为这是一个保留字.我看到一个VB代码,其中"Stop"作为方法之一.不幸的是,代码受到保护,所以我无法查看它.
如何将子程序命名为"停止"?
我有这个算法,我想在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中完成吗?