473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Square bracket usage

In the MSDN documentation I see examples like:

Dim val As [String]() = {"a", "b", "c"}

If I remove the brackets, ie, Dim val As String(), it seems to work
the same way.

What are the brackets for? And what is the difference when they are
used/omitted? I can find no mention of this anywhere in the MSDN docs.

Thanks,
Daniel Klein
Nov 20 '05 #1
5 10586
I have created string arrays (or Arrays of any type for that matter), and I
have never used the square brackets.

I think you can use them to create a variable that has the same name as a
keyword in VB.

For example:
Dim [String] As String
"Daniel Klein" <da*****@aracnet.com> wrote in message
news:t6********************************@4ax.com...
In the MSDN documentation I see examples like:

Dim val As [String]() = {"a", "b", "c"}

If I remove the brackets, ie, Dim val As String(), it seems to work
the same way.

What are the brackets for? And what is the difference when they are
used/omitted? I can find no mention of this anywhere in the MSDN docs.

Thanks,
Daniel Klein

Nov 20 '05 #2
* Daniel Klein <da*****@aracnet.com> scripsit:
In the MSDN documentation I see examples like:

Dim val As [String]() = {"a", "b", "c"}

If I remove the brackets, ie, Dim val As String(), it seems to work
the same way.
The brackets are useless in this case.
What are the brackets for? And what is the difference when they are
used/omitted? I can find no mention of this anywhere in the MSDN docs.


<http://msdn.microsoft.com/library/en-us/vbls7/html/vblrfVBSpec2_2.asp>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
The use of the square brackets allows you to use reserved words as variable
names. For example.

Dim [String]() As Integer = {1, 2, 3}

MsgBox([String](2).ToString)

However, this is not recommended practice. The practical use of the brackets
are in situations where you have no control over the names being used such
as an SQL statement where the name of a field is a reserved word.

Regards - OHM

Herfried K. Wagner [MVP] wrote:
* Daniel Klein <da*****@aracnet.com> scripsit:
In the MSDN documentation I see examples like:

Dim val As [String]() = {"a", "b", "c"}

If I remove the brackets, ie, Dim val As String(), it seems to work
the same way.


The brackets are useless in this case.
What are the brackets for? And what is the difference when they are
used/omitted? I can find no mention of this anywhere in the MSDN
docs.


<http://msdn.microsoft.com/library/en-us/vbls7/html/vblrfVBSpec2_2.asp>


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #4
* "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> scripsit:
The use of the square brackets allows you to use reserved words as variable
names. For example.

Dim [String]() As Integer = {1, 2, 3}

MsgBox([String](2).ToString)

However, this is not recommended practice. The practical use of the brackets
are in situations where you have no control over the names being used such
as an SQL statement where the name of a field is a reserved word.


Or:

\\\
Public Property [Next]() As ...
...
End Property
///

\\\
Public Sub [Stop]()
...
End Sub
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Yes, that's another excellent example.

Regards - OHM

Herfried K. Wagner [MVP] wrote:
* "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> scripsit:
The use of the square brackets allows you to use reserved words as
variable names. For example.

Dim [String]() As Integer = {1, 2, 3}

MsgBox([String](2).ToString)

However, this is not recommended practice. The practical use of the
brackets are in situations where you have no control over the names
being used such as an SQL statement where the name of a field is a
reserved word.


Or:

\\\
Public Property [Next]() As ...
...
End Property
///

\\\
Public Sub [Stop]()
...
End Sub
///


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ken in Melbourne Australia | last post by:
If I use the curly bracket syntax (referred to as the complex syntax) within a string, how do I get to call a function within it? The php manual says that the first (or previous) character for...
1
by: Veverita | last post by:
Hi there I'm hoping that someone can help me with a question I have about javascript syntax. I got an html page that uploads an image and some text field to a database. What I'd like to do...
1
by: Nalpo | last post by:
Hi, i want to update several Textboxes by reading the value of another Box. For that i use the following small script: <form name="form1" method="POST"> <input type="text" name="xx" value ="1"...
3
by: larry | last post by:
Hi, I have difficulty understanding how square brackets work in JavaScript and this is causing me difficulty retrieving the values of the options of my Select controls. My form contains many...
9
by: Christine | last post by:
It has come to my attention that sometimes, when I open a Query in SQL View, the SQL that I see is not exactly the same as the SQL in the Query's Querydef. The difference I see (only occasionally)...
2
by: Clint Olsen | last post by:
Hello: I posted a thread on comp.programming awhile back asking about an algorithm I implemented on square root. The idea was to use the square root of a prime number as a convenient way to get...
102
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
3
by: balakrishnan.dinesh | last post by:
Hi frnds, Im having a problem in searching out a particular substring in a string. Here the code: --------------------- <html> <script> var tmpString=" ";
1
by: prodziedzic | last post by:
I want use scanf to read from input everything till right square bracket ']'. It seems to be something like that: scanf("%]) but that's not working. Any ideas?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.