| Start | ||||||
|---|---|---|---|---|---|---|
| This is confusing. Why not just always use parentheses? Parentheses are used to enclose the arguments of function calls. Using them for procedure calls can cause unexpected problems. Because they can introduce bugs, both at run-time by passing a possibly unintended value to the procedure, and at compile-time by simply being invalid syntax. Run-timeRedundant parentheses can introduce bugs. Given a procedure that takes an object reference as a parameter... ...and called with parentheses: This will raise an "Object Required" runtime error #424. Other errors are possible in other circumstances: here the Parentheses force VBA to evaluate the value of the bracketed expression, and pass the result Compile-timeThis code will fail to compile: Because the expression This would compile and work: But would definitely look silly. Avoid redundant parentheses. |
||||||
Implicit Call Syntax Call a procedure by its name without any parentheses. Edge caseThe
|
||||||
Explicit Call Syntax The explicit call syntax requires the |
||||||
| Optional Arguments Some procedures have optional arguments. Optional arguments always come after required arguments, but the procedure can be called without them. For example, if the function, The structure of the function header being called here would look something like this: The You can also provide a default value for the argument in the case that a value isn't passed to the function: In this function, if the argument for |
||||||
| Return Values To retrieve the result of a procedure call (e.g. Parentheses must be present if there are parameters. If the procedure has no parameters, the parentheses are redundant. Syntax
Parameters
RemarksThe first two syntaxes are for calling See This is confusing. Why not just always use parentheses? (opens new window) for a thorough explanation of the differences between the first two syntaxes. The third syntax is for calling Fourth syntax is for calling |
Read Article
https://develop.horje.com/learn/1434/reference