How do I test if optional arguments are supplied or not?

前端 未结 8 429
后悔当初
后悔当初 2020-12-05 09:20

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          


        
8条回答
  •  囚心锁ツ
    2020-12-05 09:50

    Most of these refer to the variant type, or test if a value is blank.

    However, sometimes you want to check if a range, workbook, worksheet, or other type of object is not passed, without checking things like sheetnames.

    In that case:

    DesiredRange is Nothing
    

    Returns a boolean. For example:

        If DestinationRange Is Nothing Then
            MsgBox "Need a destination range when importing data"
        Else
            'We're happy
        End If
    

提交回复
热议问题