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

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

问题描述

如何测试是否提供了可选参数? -在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天全站免登陆