Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rules for ( ) and [ ] 2

Status
Not open for further replies.

perrymans

IS-IT--Management
Nov 27, 2001
1,340
US
If I type:

MsgBox (strUser)
or
MsgBox [strUser]

they will return the user name in a message box.

Are the ( ) and [ ] interchangeable as a general rule? Or is there a correct one to use a certain times?

Thanks. Sean.
 
The the ( ) and [ ] are not interchangeable. They just happened to produce the same results in the example you gave.

Parens ()
The () can be used to indicate a function. For Example.
SomeFunction() 'without parms
SomeFunction(aParm) 'with parms
() can be used to order the preference in a formula. For example. a * b - c is different than a * (b - c).
() can be used to indicate a subquery within a query. For example. Select a, b, (select c from tabb) as c from taba.

Brackets[]
[] is usually used to define a name with spaces. For example the field name "user name" would requre [user name] to define the field in many cases.
[] can be used to indicate a literal in a mask. For example. [#] would be to treat the # as a literal instead of a mask character.

These are just some uses but hopefully you get the idea.
 
The ( ) are used the same way you would in a math calculation (x+y)*2 = z. They Group calulations/statements together.

On the other hand [ ] is used to identify form, report, field, or control names.
For Example, if you have a Field Named My Field Num 1

To identify it you would use [My Field Num 1]
If you didn't Access would read it as [My][Field][Num][1] and return an error. This is why it is highly recomended that you don't use spaces in form, report, field, or control names.

Without spaces MyFieldNum1 is the same as [MyFieldNum1]

In your example MsgBox(strUser) and MsgBox[strUser] the reasion they both worked is because the () and the [] were ignored.
MsgBox strUser would of worked as well.


Pierre
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top