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

variable name

hello all,
I have 2 class vars:
Private _chkTemp() As CheckBox

Private WithEvents chkTemp As CheckBox

And get an error on _chkTemp:

Conflicts with 'Private Dim _chkTemp As System.Windows.Forms.CheckBox',
which is implicitly declared for 'Private Dim WithEvents chkTemp As
System.Windows.Forms.CheckBox' in class 'frmX'.

Looks like the underscore does not guarantee uniqueness of a variable. Is
there something special about underscores?

Thanks
Frank


Nov 21 '05 #1
5 1664
Hello Frank

I've run FXCop on my project and one of errors i got was :

Do not use underscores when specifying parameter names.
Some generated Visual Studio identifiers for applications
contain underscore characters. Underscore characters
should generally be avoided in public identifiers
specified in libraries.

Kind Regards
Jorge
-----Original Message-----
hello all,
I have 2 class vars:
Private _chkTemp() As CheckBox

Private WithEvents chkTemp As CheckBox

And get an error on _chkTemp:

Conflicts with 'Private Dim _chkTemp As System.Windows.Forms.CheckBox',which is implicitly declared for 'Private Dim WithEvents chkTemp AsSystem.Windows.Forms.CheckBox' in class 'frmX'.

Looks like the underscore does not guarantee uniqueness of a variable. Isthere something special about underscores?

Thanks
Frank


.

Nov 21 '05 #2
"Frank" <fr***@frank.com> wrote in message
news:ch**********@news2.tilbu1.nb.home.nl...
hello all,
I have 2 class vars:
Private _chkTemp() As CheckBox

Private WithEvents chkTemp As CheckBox

And get an error on _chkTemp:

Conflicts with 'Private Dim _chkTemp As System.Windows.Forms.CheckBox',
which is implicitly declared for 'Private Dim WithEvents chkTemp As
System.Windows.Forms.CheckBox' in class 'frmX'.

Looks like the underscore does not guarantee uniqueness of a variable. Is
there something special about underscores?

Thanks
Frank


If you run ildasm against one of your exe or dlls (I am using a aspx.net
dll) you will find each of the 'withevents' objects seems to be translated
by vb into a property which gets/sets a private variable with the same name
prefixed by an underscore.
I cant say if its a VB thing only or .net in general.

--
Jonathan Bailey.
Nov 21 '05 #3
* "Frank" <fr***@frank.com> scripsit:
I have 2 class vars:
Private _chkTemp() As CheckBox

Private WithEvents chkTemp As CheckBox

And get an error on _chkTemp:

Conflicts with 'Private Dim _chkTemp As System.Windows.Forms.CheckBox',
which is implicitly declared for 'Private Dim WithEvents chkTemp As
System.Windows.Forms.CheckBox' in class 'frmX'.

Looks like the underscore does not guarantee uniqueness of a variable. Is
there something special about underscores?


Yes, there is something special about underscores. VB.NET generates
fields automatically and the names of these fields begin with '_'. So
you will have a name conflict.

I suggest to use the 'm_' prefix instead, because this prefix will avoid
those clashes and it will make code better readable, especially when
procedure separators are turned on.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4
> ...better readable, especially when procedure separators are turned on.

That is definately true.

Now I finally have two good reasons to stop using _ prefixes.

Greg
Nov 21 '05 #5
On 2004-09-10, <jb> <> wrote:
"Frank" <fr***@frank.com> wrote in message
news:ch**********@news2.tilbu1.nb.home.nl...

If you run ildasm against one of your exe or dlls (I am using a aspx.net
dll) you will find each of the 'withevents' objects seems to be translated
by vb into a property which gets/sets a private variable with the same name
prefixed by an underscore.
I cant say if its a VB thing only or .net in general.
It's a VB thing. VB needs a way to call AddHandler/RemoveHandler
whenever you assign to the variable, so it hides the "WithEvents" field
behind a property.

None of the other major .NET languages do this, but it's possible that a
few of the less popular compilers might do the same thing, I don't know.

Nov 21 '05 #6

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

Similar topics

1
by: Scott | last post by:
I have an XML Document in a format like: <Variable name="Bob">ABCDEFG</Variable> <Variable name="Steve">QWERTYUI</Variable> <Variable name="John">POIUYTR</Variable> <Variable...
2
by: Bradford | last post by:
Question for the masses... Lets say I have variable with the following contents "aaaa bbbb ccccc dddd". The format is not specific and the space delimiter could be changed to any other. How...
4
by: Frederik Sørensen | last post by:
I include a xslt stylesheet with variables for all the error messages in my system. <xsl:variable name="Banner_error_1"> errormessage 1 for banner </xsl:variable> <xsl:variable...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
3
by: rls03 | last post by:
I have the following which creates a variable containing a relative path where <xsl:value-of select="."/returns a portion of the filename: <xsl:variable...
2
by: Kevin | last post by:
I am having difficulty updating a variable page-time-stamp in the following snippit. The variable time-stamp is initialized from the attribute time-stamp from the log element. Some of the page...
2
by: Looch | last post by:
All, I'm trying to output but I can only get (brackets for clarity) when using the code below. How can I "break" into the query variable in the InsertName method to add the name parameter to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.