473,405 Members | 2,185 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,405 software developers and data experts.

What Does This Mean?

I found this statement in some sample code. It seems to be syntactically
correct. What do the brackets around "String" mean?

Dim sWork As [String] = "Some number of characters"

Dec 11 '06 #1
13 1966
"Herman Jones" <He*********@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
>I found this statement in some sample code. It seems to be syntactically
correct. What do the brackets around "String" mean?

Dim sWork As [String] = "Some number of characters"
They are used indicate the item in the brackets is not a keyword. For
example if you wanted to name a variable Dim you might be able to do this:

Dim [Dim] as Int32
[Dim] = 5

I'm not sure if that works but that the sort of thing it's used for. It
could be used for function names, class names etc. In the case of String
above it does nothing but doesn't cause any problems either. You can remove
them.

Michael
Dec 11 '06 #2
This example seems to be a little different. In your example you're using
[Dim] as a variable name. It comes before the "As" keyword.

The sample code I found has [String] after the "As" keyword. I don't thing
that "String" is being used as the variable name because the program later
refers to the "sWork" variable.

Is it possible that the brackets have some other purpose when they bracket a
datatype?

"Michael C" wrote:
"Herman Jones" <He*********@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
I found this statement in some sample code. It seems to be syntactically
correct. What do the brackets around "String" mean?

Dim sWork As [String] = "Some number of characters"

They are used indicate the item in the brackets is not a keyword. For
example if you wanted to name a variable Dim you might be able to do this:

Dim [Dim] as Int32
[Dim] = 5

I'm not sure if that works but that the sort of thing it's used for. It
could be used for function names, class names etc. In the case of String
above it does nothing but doesn't cause any problems either. You can remove
them.

Michael
Dec 11 '06 #3
"Herman Jones" <He*********@discussions.microsoft.comwrote in message
news:2E**********************************@microsof t.com...
This example seems to be a little different. In your example you're using
[Dim] as a variable name. It comes before the "As" keyword.

The sample code I found has [String] after the "As" keyword. I don't
thing
that "String" is being used as the variable name because the program later
refers to the "sWork" variable.

Is it possible that the brackets have some other purpose when they bracket
a
datatype?
The dim was just 1 example, it can be used in many places. If a program had
a datatype called "As" then you'd need to do Dim x as [As]

Michael
Dec 11 '06 #4
>I found this statement in some sample code. It seems to be syntactically
correct. What do the brackets around "String" mean?

Dim sWork As [String] = "Some number of characters"
That the programmer of this program is probably an idiot.
You replace with this the general meaning of the keyword.

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As New [String](1)
Dim b As String = "What the hell is this"
End Sub
End Class
Public Class [String]
Public Sub New(ByVal b As Integer)
b = b
End Sub
Public b As Integer
End Class

Cor
Dec 11 '06 #5
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Public Sub New(ByVal b As Integer)
b = b
End Sub
Public b As Integer
Does that actually work in vb.net?

Michael
Dec 11 '06 #6
It runs and gives very strange results.

Cor

"Michael C" <no****@nospam.comschreef in bericht
news:OF**************@TK2MSFTNGP02.phx.gbl...
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
> Public Sub New(ByVal b As Integer)
b = b
End Sub
Public b As Integer

Does that actually work in vb.net?

Michael

Dec 11 '06 #7
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:u%****************@TK2MSFTNGP03.phx.gbl...
It runs and gives very strange results.
Would it just leave this.b = 0 or uninitialised?

Michael
Dec 11 '06 #8
Try it and find out!
"Michael C" <no****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:u%****************@TK2MSFTNGP03.phx.gbl...
>It runs and gives very strange results.

Would it just leave this.b = 0 or uninitialised?

Michael

Dec 11 '06 #9
zero

"Michael C" <no****@nospam.comschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:u%****************@TK2MSFTNGP03.phx.gbl...
>It runs and gives very strange results.

Would it just leave this.b = 0 or uninitialised?

Michael

Dec 11 '06 #10
Herman,

No, the bracket does not have alternate meaning when used with data
types. Brackets allow you to create escaped or verbatim identifiers.
This is useful when you need to refer to an identifier that is also a
keyword. The most common scenario is the interaction between different
programming languages. For example, a C# programmer may think Alias
would be a good choice for a property name not knowing that it is a
keyword in VB. A VB programmer would need to use brackets when
referring to that property.

Brian

Herman Jones wrote:
This example seems to be a little different. In your example you're using
[Dim] as a variable name. It comes before the "As" keyword.

The sample code I found has [String] after the "As" keyword. I don't thing
that "String" is being used as the variable name because the program later
refers to the "sWork" variable.

Is it possible that the brackets have some other purpose when they bracket a
datatype?
Dec 11 '06 #11
Herman,

No, the bracket does not have alternate meaning when used with data
types. Brackets allow you to create escaped or verbatim identifiers.
This is useful when you need to refer to an identifier that is also a
keyword. The most common scenario is the interaction between different
programming languages. For example, a C# programmer may think Alias
would be a good choice for a property name not knowing that it is a
keyword in VB. A VB programmer would need to use brackets when
referring to that property.

Brian

Herman Jones wrote:
This example seems to be a little different. In your example you're using
[Dim] as a variable name. It comes before the "As" keyword.

The sample code I found has [String] after the "As" keyword. I don't thing
that "String" is being used as the variable name because the program later
refers to the "sWork" variable.

Is it possible that the brackets have some other purpose when they bracket a
datatype?
Dec 11 '06 #12

"Herman Jones" <He*********@discussions.microsoft.comwrote in
message news:6F**********************************@microsof t.com...
:
: I found this statement in some sample code. It seems to be
: syntactically correct. What do the brackets around "String"
: mean?
:
: Dim sWork As [String] = "Some number of characters"
I don't see the point of using the brackets in this context. I checked
out the complete code you included in the other post and it compiles
just fine with or without the brackets. Just out of curiousity, I
compared both versions of the code in the ildasm utility and the vb
compiler emitted the exact same code. In this instance, the brackets
are meaningless. That said, brackets are quite useful. Indeed, they
are often necessary.

Let's say you have access to an email message class written in C#
which exposes the following Properties:

From
To
Subject
Body
If you were to declare an instance of this class in vb, you'd have a
problem because "To" is a vb keyword. The following would fail:

With New CSharpEmailMessageType
.From = "Me@MyDomain.com"
.To = "Yo*@YourDomain.com"
.Subject = "Hello"
.Body = "World"
End With

This would not compile. To get around this, you would need to do the
following:

With New CSharpEmailMessageType
.From = "Me@MyDomain.com"
.[To] = "Yo*@YourDomain.com"
.Subject = "Hello"
.Body = "World"
End With

Now the code would compile just fine. Brackets tell the compiler to
treat what would otherwise be a reserved keyword as any other code
element.

Another use I've personally found for the brackets is when I'm
generating throw away code. I don't post to this forum often, but
occasionally I will offer a code example to a question. In those
cases, I may post a complete example that will compile and run. For
example, I might do something like this:

=======================================
Option Strict

Imports Microsoft.VisualBasic
Imports System

Public Module [module]
Public Sub Main
Dim c As New [class]
Console.WriteLine(c.GetMessage)
End Sub
End Module

Public Class [class]
Public Function GetMessage() As String
Return "Hello World" & vbCrLf
End Function
End Class
=======================================
I defined a module and a class but really didn't want to waste time
trying to figure out a clever or relevant name for them, so I just
named them '[module]' and '[class]' and moved on from there.
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
Dec 12 '06 #13
_Anon,

Nobody discuss that they can be handy. I do not believe that there is a
serious person who would give String another name even not somebody from who
is selling underwear.

Cor

"_AnonCoward" <ab****@uvwxyz.comschreef in bericht
news:yh****************@tornado.southeast.rr.com.. .
>
"Herman Jones" <He*********@discussions.microsoft.comwrote in
message news:6F**********************************@microsof t.com...
:
: I found this statement in some sample code. It seems to be
: syntactically correct. What do the brackets around "String"
: mean?
:
: Dim sWork As [String] = "Some number of characters"
I don't see the point of using the brackets in this context. I checked
out the complete code you included in the other post and it compiles
just fine with or without the brackets. Just out of curiousity, I
compared both versions of the code in the ildasm utility and the vb
compiler emitted the exact same code. In this instance, the brackets
are meaningless. That said, brackets are quite useful. Indeed, they
are often necessary.

Let's say you have access to an email message class written in C#
which exposes the following Properties:

From
To
Subject
Body
If you were to declare an instance of this class in vb, you'd have a
problem because "To" is a vb keyword. The following would fail:

With New CSharpEmailMessageType
.From = "Me@MyDomain.com"
.To = "Yo*@YourDomain.com"
.Subject = "Hello"
.Body = "World"
End With

This would not compile. To get around this, you would need to do the
following:

With New CSharpEmailMessageType
.From = "Me@MyDomain.com"
.[To] = "Yo*@YourDomain.com"
.Subject = "Hello"
.Body = "World"
End With

Now the code would compile just fine. Brackets tell the compiler to
treat what would otherwise be a reserved keyword as any other code
element.

Another use I've personally found for the brackets is when I'm
generating throw away code. I don't post to this forum often, but
occasionally I will offer a code example to a question. In those
cases, I may post a complete example that will compile and run. For
example, I might do something like this:

=======================================
Option Strict

Imports Microsoft.VisualBasic
Imports System

Public Module [module]
Public Sub Main
Dim c As New [class]
Console.WriteLine(c.GetMessage)
End Sub
End Module

Public Class [class]
Public Function GetMessage() As String
Return "Hello World" & vbCrLf
End Function
End Class
=======================================
I defined a module and a class but really didn't want to waste time
trying to figure out a clever or relevant name for them, so I just
named them '[module]' and '[class]' and moved on from there.
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.


Dec 12 '06 #14

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification...
2
by: Steve Richter | last post by:
What does the "." mean in the following sql script stmts? use GO if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id,N'IsUserTable') = 1) drop table ....
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.