如何测试是否提供了可选参数? [英] How do I test if optional arguments are supplied or not?

查看:25
本文介绍了如何测试是否提供了可选参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试是否提供了可选参数?-- 在 VB6/VBA 中

How do I test if optional arguments are supplied or not? -- in VB6 / VBA

Function func (Optional ByRef arg As Variant = Nothing)

    If arg Is Nothing Then   <----- run-time error 424 "object required"
        MsgBox "NOT SENT"
    End If

End Function 

推荐答案

使用 IsMissing:

If IsMissing(arg) Then
    MsgBox "Parameter arg not passed"
End If

但是,如果我没记错的话,这在为参数提供默认值时不起作用,并且在任何情况下都会使使用默认参数变得相当多余.

However, if I remember correctly, this doesn’t work when giving a default for the argument, and in any case it makes using the default argument rather redundant.

这篇关于如何测试是否提供了可选参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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