473,789 Members | 3,013 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using brackets to describe root classes in VB.Net - maybe?

7 New Member
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 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 out...

Here's what I know about brackets - If they are used around a reserved word then that becomes a usable (escaped) name (i.e. Dim [String] as Integer). If they are used around a type in a DIM or NEW type statement then they're redundant and actually go away (i.e. Dim MyString as [String]).

Here's my problem:
There is at least one time in the documentation where brackets aren't used for escaping, nor do they seem to be redundant (an error occurs if they aren't there), but I can't seem to find documentation to tell me why they ARE needed (I hate it when I don't know WHY I should do things)!

Can anyone give me a reference where this is explained? Thanks!

Here's the code (Straight from the VS2005 help doc)
Confusing piece is on lines 13, 14, and 18 - "[Enum]"

Expand|Select|Wrap|Line Numbers
  1.   Public Class ParseTest
  2.    Enum Colors
  3.      Red = 1
  4.      Green = 2
  5.      Blue = 4
  6.      Yellow = 8
  7.    End Enum
  8.  
  9.    Public Shared Sub Main()
  10.       Dim colorName As String
  11.  
  12.       Console.WriteLine("The entries of the Colors Enum are:")
  13.       For Each colorName In [Enum].GetNames(GetType(Colors))
  14.          Console.WriteLine("{0}={1}", colorName, Convert.ToInt32([Enum].Parse(GetType(Colors), colorName)))
  15.       Next colorName
  16.       Console.WriteLine()
  17.  
  18.       Dim myOrange As Colors = CType([Enum].Parse(GetType(Colors), "Red, Yellow"), Colors)
  19.       Console.WriteLine("The myOrange value {1} has the combined entries of {0}", myOrange, Convert.ToInt64(myOrange))
  20.    End Sub
  21. End Class
  22.  
(code is from http://msdn2.microsoft.com/en-us/library/essfb559.aspx)
Sep 21 '07 #1
5 1466
Plater
7,872 Recognized Expert Expert
It almost looks like they're used to specifuy a typecast to a custom object (i.e. the custom enum of Colors you just made)
Or it might be similar to the Me. (or this. if you're in C#) like you suggested?

Have you tried running the code without the brackets?
Sep 21 '07 #2
alan4cast
7 New Member
Have you tried running the code without the brackets?
Sort of. Removing them gets an "Expression Expected" error.
(An operator such as + or = requires an expression for its right operand, but no recognizable expression appears.Error ID: BC30201)

It almost looks like they're used to specify a typecast to a custom object (i.e. the custom enum of Colors you just made)Or it might be similar to the Me.
I thought that it might be a custom class that's part of System... Actually, I just tried "System.Enu m" instead of [Enum]... that worked with no error. So... does the bracket then look for an underlying version of an object, or does it relate to an imported class or...?
Sep 21 '07 #3
Plater
7,872 Recognized Expert Expert
Well i'm not sure, BUT I have always wondered if it was possible to itterate through an enum, so that looks pretty cool there.
Sep 21 '07 #4
alan4cast
7 New Member
Well I'm not sure, BUT I have always wondered if it was possible to iterate through an enum, so that looks pretty cool there.
Looks like you can!

I actually found the code in question while trying to help with an XML-ish text file save methodology I'm using to restore the value of an enum based on a text string. (e.g. the "Parse" function shown above.

I'll go under the assumption that the brackets are used to refer to an underlying imported class type that is also a keyword. (Unless someone else tells me different!)

Thanks!
Sep 21 '07 #5
Frinavale
9,735 Recognized Expert Moderator Expert
I'm looking into this more...it's something I don't know.
I just found out that if you type "enum" into the search function for the MSDN Library...it crashes...

But!
If you type [enum] for the search...
It doesn't crash

crazy...
Sep 21 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2493
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. I've made a small list of some good and bad points of both. These points don't really go into the grammar aspects of these languages, but are more about secondary aspects. The grammar aspects are different, but both are suitable for validating...
28
20346
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()', this.pinginterval); - but is there no way to do this without using the literal ObjectName? If I write 'this.methodName()' I get "Line 1 Char 1: Object doesn't support this property or method." in IE, and nothing happens in Firebird.
6
4841
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms Authentication set up and it worked just fine. Then I realized that I needed to have some pages unsecure. I then created 2 directories. One named Secure and the other named Public. I placed my web.config file in my
11
2138
by: TGF | last post by:
I am wondering if it is feasible to use .NET for applications that have to be very fast. We have a few applications that are blazingly fast, written in Borland C++ using Borland C++ Builder. We would like to port over to ..NET, but some of the test models we have developed are MUCH, MUCH slower than it's Borland counterpart. Is this due to the .NET Framework and the JIT? Or is it something we should be looking for in the project...
2
4478
by: sp | last post by:
Hello Everybody, I need to convert xml that we get from sqlserver For xml auto to my own xml format using asp.net classes. Any ideas and suggestions would be appreciated. Thanks in Advance sp
3
6808
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
1
5184
by: chidam.chidam | last post by:
Hi all, I would like to implement log4net for logging my application. First let me describe in short about the application. I have a solution with two exe file outputs and several dll assemblies. And my application has a different AppDomain as it is a customization of another COM based application written in VB.NET. I have tried with App.Config files in my startup exe applications. It works fine only till the parent application is...
68
4656
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a temporary but it was stated that it would not. This has come up in an irc channel but I can not find the original thread, nor can I get any code to work. Foo& Bar( int Val ) { return Foo( Val ); }
15
1792
by: r0g | last post by:
Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a class e.g. class Foo(): bar = 1 gum = 2
0
10199
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
10139
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,...
0
9983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
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
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
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.