View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Edwin Tam (MS MVP) Edwin Tam (MS MVP) is offline
external usenet poster
 
Posts: 48
Default 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