Re: What Does This Mean?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



_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" <abcdef@xxxxxxxxxx> schreef in bericht
news:yhqfh.5261$dD2.673@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Herman Jones" <HermanJones@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:6F3326FF-B08F-4729-A6AB-80AD27F9EA27@xxxxxxxxxxxxxxxx
:
: 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@xxxxxxxxxxxx"
.To = "You@xxxxxxxxxxxxxx"
.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@xxxxxxxxxxxx"
.[To] = "You@xxxxxxxxxxxxxx"
.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.




.



Relevant Pages

  • Re: What Does This Mean?
    ... : syntactically correct. ... I don't see the point of using the brackets in this context. ... Now the code would compile just fine. ... Public Function GetMessageAs String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: PRODUCT calculation in queries
    ... The Microsoft Jet database engine could not find the input table or query ... After pasting it into the code window, choose Compile on the Debug menu. ... Function Product(strField As String, strTable As String, _ ... Dim dblResult As Double ...
    (microsoft.public.access.queries)
  • Re: edit-replace function
    ... original search string (and if you paste the string from your message into ... original document by viewing the space characters with CTRL+* a space will ... The brackets are there only to ... Lewis Shanks wrote:> Jon: ...
    (microsoft.public.word.customization.menustoolbars)
  • Re: Help a beginner - simple lowercase to uppercase and so on function
    ... can understand everything but it should take shape with more practice ... it compiles and returns uppercase letters ... in this string!" ... to compile on both. ...
    (comp.lang.c)
  • Re: macro to remove item between parenthesis
    ... the last opening bracket in the string and moves the start of the range to ... Word MVP web site http://word.mvps.org ... macros look for the first open parenthesis and then highlight ... bracketed strings or if you have missing brackets, ...
    (microsoft.public.word.docmanagement)