473,385 Members | 1,753 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,385 software developers and data experts.

brackets around types?

i was just looking at the tcplistener example on the MSDN docs and saw this

Dim bytes(1024) As [Byte]
Dim data As [String] = Nothing

the data types ar ein brackets, what is the significance of the brackets?
and when i type them into vb.net 2003 the brackets remove themself... why
are they there, what do they do? thanks!
Nov 20 '05 #1
7 6788
"Brian Henry" <NO************@adelphia.net> schrieb
i was just looking at the tcplistener example on the MSDN docs and
saw this

Dim bytes(1024) As [Byte]
Dim data As [String] = Nothing

the data types ar ein brackets, what is the significance of the
brackets? and when i type them into vb.net 2003 the brackets remove
themself... why are they there, what do they do? thanks!


In your example the brackets are superfluous.

To use reserved keywords as identifiers, the brackets must be used to
distinguish between the identifier and the keyword:

dim [String] As String

public sub [Stop]
end sub

see also:
http://msdn.microsoft.com/library/en...amesInCode.asp
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Hi Brian,

In your examples:

Dim bytes(1024) As [Byte]
Dim data As [String] = Nothing

they do absolutely nothing (which is why they get removed without loss).

In this, though:

Dim [Byte](1024) As Byte
Dim [String] As String = Nothing
[String] = "Poor choice of variable name"

the [] around the names allows you to use a reserved word. The compiler
won't object because you're telling it that you know what you're doing.

Very few people would want to call their variables Byte or String but it's
allowed when [] is used.

Here's a decent example:
Class StopWatch : Inherits Clock
Public Sub Start
'Note the start time.
End Sub

Public Sub [Stop]
'Record the time taken.
End Sub
End Class

'Stop' is a reserved word but it's more than reasonable that a StopWatch
has a Stop method!! So it needs the [] around it in the declaration.

However, in use, unlike the [Byte] and [String] above, you wouldn't need
the [] with Stop because it will be partnered with a StopWatch object.

oStopWatch.Start
'Do something
oStopWatch.Stop
Console.WriteLine (oStopWatch.Elapsed ("ms"))

For the compiler there's no possibilty that the 'Stop' in oStopWatch.Stop
is a reserved word so the [] are not needed.

Regards,
Fergus

--
(Please ignore this - there's a feud going on)
==================================================
Quote of the day
Herfried:
I don't need/want human interaction.
==================================================
Nov 20 '05 #3
makes me kinda wonder why MSDN put them in there documentation for
tcplistener...
"Fergus Cooney" <fi****@post.com> wrote in message
news:OH*************@TK2MSFTNGP10.phx.gbl...
Hi Brian,

In your examples:

Dim bytes(1024) As [Byte]
Dim data As [String] = Nothing

they do absolutely nothing (which is why they get removed without loss).
In this, though:

Dim [Byte](1024) As Byte
Dim [String] As String = Nothing
[String] = "Poor choice of variable name"

the [] around the names allows you to use a reserved word. The compiler won't object because you're telling it that you know what you're doing.

Very few people would want to call their variables Byte or String but it's allowed when [] is used.

Here's a decent example:
Class StopWatch : Inherits Clock
Public Sub Start
'Note the start time.
End Sub

Public Sub [Stop]
'Record the time taken.
End Sub
End Class

'Stop' is a reserved word but it's more than reasonable that a StopWatch has a Stop method!! So it needs the [] around it in the declaration.

However, in use, unlike the [Byte] and [String] above, you wouldn't need the [] with Stop because it will be partnered with a StopWatch object.

oStopWatch.Start
'Do something
oStopWatch.Stop
Console.WriteLine (oStopWatch.Elapsed ("ms"))

For the compiler there's no possibilty that the 'Stop' in oStopWatch.Stop is a reserved word so the [] are not needed.

Regards,
Fergus

--
(Please ignore this - there's a feud going on)
==================================================
Quote of the day
Herfried:
I don't need/want human interaction.
==================================================

Nov 20 '05 #4
Hi Brian,

I have the 2001 MSDN Help at home and there's an old version of that
code with [Byte] but the new one on the MSDN has more of them. Maybe
it was a translation from some C# by someone who wasn't quite sure? It's
certainly wierd. I mailed them some feedback from the link at the bottom.

Regards,
Fergus
Nov 20 '05 #5
* "Brian Henry" <NO************@adelphia.net> scripsit:
i was just looking at the tcplistener example on the MSDN docs and saw this

Dim bytes(1024) As [Byte]
Dim data As [String] = Nothing

the data types ar ein brackets, what is the significance of the brackets?
and when i type them into vb.net 2003 the brackets remove themself... why
are they there, what do they do?


See:

<http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconkeywordsascontrolnamesincode.asp>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #6
* "Brian Henry" <NO************@adelphia.net> scripsit:
makes me kinda wonder why MSDN put them in there documentation for
tcplistener...


For example in the docs for 'TcpListener.AcceptSocket' they don't make
sense.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #7
that is what threw me off... the fact it was around the data type, i knew
about reserved words with brackets because of working with sql server and
similar circumstances... but brackets around a data type just was like what
the hehe..

thanks everyone
"Fergus Cooney" <fi****@post.com> wrote in message
news:Ok**************@TK2MSFTNGP12.phx.gbl...
Hi Brian,

I have the 2001 MSDN Help at home and there's an old version of that
code with [Byte] but the new one on the MSDN has more of them. Maybe
it was a translation from some C# by someone who wasn't quite sure? It's
certainly wierd. I mailed them some feedback from the link at the bottom.

Regards,
Fergus

Nov 20 '05 #8

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

Similar topics

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...
6
by: STF | last post by:
While reading the C++ tutorial in this page: http://www.cplusplus.com/doc/tutorial/tut2-2.html I'm astonished to learn that we could omit curly brackets in function declaration for single...
4
by: Smitro | last post by:
Hi, How come in some statements I can use: If (something) or DIE(); but other times it won't work (returns an error) unless I take out the OR. Is there any documentation on this anywhere?
3
by: Eric Ellsworth | last post by:
Hi all, Does anyone have any bright ideas for Access' tendency to add square brackets when it parses queries, then tell you that the query syntax is invalid. In my case, I'm trying to do a LEFT...
1
by: Greg | last post by:
I have an Access db (actually, about 60 of them) that has a table with a field named Q#. This table gets read into a dataset. In the dataset, the field is also called Q#. But when I try to update...
1
by: Greg Strong | last post by:
Hello All, Why would brackets be added to the SQL of a pass through query to Oracle? If I paste the debug print of the SQL statement into SQLPlus of Oracle's XE edition it works, and does NOT...
0
by: alan4cast | last post by:
I'm not a really new programmer, but I'm still working on learning all of the .net things that I should know. So when I came across this one, I started to dig into it so see if I could figure it...
5
by: alan4cast | last post by:
I posted this in the VB forum several days ago, and got no reply. Since it's specific to VB.Net I thought I'd try it here. I'm a relatively-experienced VB programmer, but I'm still working on...
4
by: Keith Hughitt | last post by:
Hi all, I am using someone else's script which expects input in the form of: ./script.py <arg1arg2 I was wondering if the angle-brackets here have a special meaning? It seems like they...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.