使用可选参数运行子过程 [英] Running sub procedure with optional argument

查看:74
本文介绍了使用可选参数运行子过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,我想知道它是否被另一个程序调用。所以我做了类似的事情:



Sub MyProcName(可选CalledFromProc为布尔值)



然后当我调用程序时,我就这样做:


MyProcName(True)


好的,好的。但我也想要自己运行程序。但是,因为我已经包含了一个参数,所以我不能单独运行它。有没有更好的方法呢?



tod



解决方案

您可以使用

 MyProcName 

调用MyProcName 

进行调用没有传递CalledFromProc参数的过程。当您在MyProcName 过程中检查CalledFromProc时,其值将为False,因为如果您没有明确指定它,那么这是布尔值的默认值。


所以你可以创建一个宏

 Sub RunMyProcName()
调用MyProcName
End Sub


运行MyProcName点。


I have a procedure and I want to know if it was called by another procedure or not. So I did something like this:

Sub MyProcName(Optional CalledFromProc As Boolean)

Then when I call the procedure I just do this:

MyProcName(True)

Okay, fine. But I also want to just run the procedure by itself. However, because I've included an argument I can not run it by itself. Is there a better way to do this?

tod

解决方案

You can use

    MyProcName

or

    Call MyProcName

to call the procedure without passing the CalledFromProc argument. When you check CalledFromProc within the MyProcName procedure, its value will be False, since that is the default value of a Boolean if you don't specify it explicitly.

So you could create a macro

Sub RunMyProcName()
    Call MyProcName
End Sub

to run MyProcName.


这篇关于使用可选参数运行子过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆