ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Arguments and brackets (https://www.excelbanter.com/excel-programming/282740-arguments-brackets.html)

David

Arguments and brackets
 
Greetings,
Please help with my VBA education:
Sometimes arguments are in brackets, sometimes not. What
are the criteria for use of brackets with arguments?
TIA
David

Edwin Tam (MS MVP)

Arguments and brackets
 
Let's learn using examples

First, for Msgbox, if you got values for the second, third (and so on) arguments, you must not use brackets
For example
MsgBox "Hello World!", vbYesNo, "This is the Title
If you add brackets: MsgBox ("Hello World!", vbYesNo, "This is the Title"
Excel will return an error

However, for Inputbox, because you always need to assign the value to a variable, you always need to use brackets. For example

Dim
x = InputBox("Are you ok?", vbYesNo,"Yes"

Another example. If you have a VBA function called "hello", the syntax is

hello(boy, girl

When calling the function in a macro procedure, normally, you assign the value to a variable. You always need to use brackets. For example

Dim
x = hello(1, 2

So, at this point, you may have a idea that, whenever you assign something to a variable, you use brackets. Otherwise, you don't need to use brackets

Another example. You got a subroutine with an arguement

Private Sub macro1(hh
Msgbox h
End Su

You want to call the above Sub from another Sub

Sub calling(
macro1 "hello!
end su

Note here. This example further shows you that in case you're not assigning something to a variable, you don't use brackets


----- David wrote: ----

Greetings
Please help with my VBA education
Sometimes arguments are in brackets, sometimes not. What
are the criteria for use of brackets with arguments
TI
Davi


David

Arguments and brackets
 
Thanks Edwin for your illuminating response.
I see the brackets are waiting to accept a variable for
assignment
David



All times are GMT +1. The time now is 10:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com