Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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  
like image 234
Robin Rodricks Avatar asked Nov 02 '09 11:11

Robin Rodricks


People also ask

How do you indicate optional arguments?

To indicate optional arguments, Square brackets are commonly used, and can also be used to group parameters that must be specified together. To indicate required arguments, Angled brackets are commonly used, following the same grouping conventions as square brackets.

What is an optional argument What does Excel do if you do not include an optional argument?

When you call a procedure with an optional argument, you can choose whether or not to specify the optional argument. If you don't specify the optional argument, the default value, if any, is used. If no default value is specified, the argument would be for any variable of the specified type.

How do you get optional arguments in Python?

You can assign an optional argument using the assignment operator in a function definition or using the Python **kwargs statement. There are two types of arguments a Python function can accept: positional and optional. Optional arguments are values that do not need to be specified for a function to be called.

How do you fix an argument not optional in VBA?

To correct this error If they are not, either supply the argument in the call, or declare the parameter Optional in the definition.


1 Answers

Use 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.

like image 120
Konrad Rudolph Avatar answered Oct 06 '22 23:10

Konrad Rudolph