473,804 Members | 3,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
13 1998
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*********@di scussions.micro soft.comwrote in
message news:6F******** *************** ***********@mic rosoft.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 CSharpEmailMess ageType
.From = "Me@MyDomain.co m"
.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 CSharpEmailMess ageType
.From = "Me@MyDomain.co m"
.[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.Visua lBasic
Imports System

Public Module [module]
Public Sub Main
Dim c As New [class]
Console.WriteLi ne(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

"_AnonCowar d" <ab****@uvwxyz. comschreef in bericht
news:yh******** ********@tornad o.southeast.rr. com...
>
"Herman Jones" <He*********@di scussions.micro soft.comwrote in
message news:6F******** *************** ***********@mic rosoft.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 CSharpEmailMess ageType
.From = "Me@MyDomain.co m"
.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 CSharpEmailMess ageType
.From = "Me@MyDomain.co m"
.[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.Visua lBasic
Imports System

Public Module [module]
Public Sub Main
Dim c As New [class]
Console.WriteLi ne(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
14866
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 software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
3
29685
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 says: "The 'visibility' property takes the value 'collapse' for row, row group, column, and column group elements. This value causes the entire row or column to be removed from the display, and the space normally taken up by the row or column to...
2
10222
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 . GO
121
10196
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 support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
13
5063
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
10575
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7616
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.