473,503 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When and Why use "Me."?

Hello,

I realize that this is a very basic question but is there an advantage to
using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.

Thanks,
Richard
Nov 21 '05 #1
14 10755
Me is a handy reference if you cant remember the object name, intellisense
will give you a list.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
Hello,

I realize that this is a very basic question but is there an advantage to
using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.

Thanks,
Richard

Nov 21 '05 #2
Richard,

Me is mostly just used as an easy shortcut to intelisence, for the rest it
makes no sense with the little exception when there is an ambigious name
used in your program. Than you can use it as well to make that name unique.
I think that a better name had been My. It are all things that directly
belongs to the class. However I am not a person wich native language is
English so I have to be a little bit carefull with telling this.

I hope this helps?

Cor

"Richard Thornley" <rh**@thorsoft.com>
Hello,

I realize that this is a very basic question but is there an advantage to
using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.

Thanks,
Richard

Nov 21 '05 #3
Thank You for the explaination. That is what I thought it was for but
sometimes a simple answer is difficult to find in a manual or book.

Cheers,

Richard

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Me is a handy reference if you cant remember the object name, intellisense
will give you a list.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
Hello,

I realize that this is a very basic question but is there an advantage to
using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.

Thanks,
Richard


Nov 21 '05 #4
Thank You for the explaination. That is what I thought it was for but
sometimes a simple answer is difficult to find in a manual or book.

Cheers,

Richard

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OD**************@TK2MSFTNGP10.phx.gbl...
Richard,

Me is mostly just used as an easy shortcut to intelisence, for the rest
it makes no sense with the little exception when there is an ambigious
name used in your program. Than you can use it as well to make that name
unique. I think that a better name had been My. It are all things that
directly belongs to the class. However I am not a person wich native
language is English so I have to be a little bit carefull with telling
this.

I hope this helps?

Cor

"Richard Thornley" <rh**@thorsoft.com>
Hello,

I realize that this is a very basic question but is there an advantage to
using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.

Thanks,
Richard


Nov 21 '05 #5
Couldn't Me also be substituted for MyClass?
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Me is a handy reference if you cant remember the object name, intellisense
will give you a list.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
Hello,

I realize that this is a very basic question but is there an advantage to using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.

Thanks,
Richard


Nov 21 '05 #6
The "me" reference exists so that an object can pass references of itself to
other classes and methods.

using me.member (etc) is handy for Intellisence (as people have already
noted), but it may also speed up compilation time, as the compilier doesn't
have to look through the entire symbol table to resolve the entry.

"Richard Thornley" wrote:
Hello,

I realize that this is a very basic question but is there an advantage to
using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.

Thanks,
Richard

Nov 21 '05 #7
Yes, good point MyClass enables you to refer to the current object.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:OS*************@TK2MSFTNGP15.phx.gbl...
Thank You for the explaination. That is what I thought it was for but
sometimes a simple answer is difficult to find in a manual or book.

Cheers,

Richard

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OD**************@TK2MSFTNGP10.phx.gbl...
Richard,

Me is mostly just used as an easy shortcut to intelisence, for the rest
it makes no sense with the little exception when there is an ambigious
name used in your program. Than you can use it as well to make that name
unique. I think that a better name had been My. It are all things that
directly belongs to the class. However I am not a person wich native
language is English so I have to be a little bit carefull with telling
this.

I hope this helps?

Cor

"Richard Thornley" <rh**@thorsoft.com>
Hello,

I realize that this is a very basic question but is there an advantage
to using Me.ControlName.Text over just using ControlName.Text? I have
been leaving the Me. off but would include it if there are benefits.

Thanks,
Richard



Nov 21 '05 #8
Yes, good point MyClass enables you to refer to the current object.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:eH**************@TK2MSFTNGP09.phx.gbl...
Couldn't Me also be substituted for MyClass?
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Me is a handy reference if you cant remember the object name,
intellisense
will give you a list.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> I realize that this is a very basic question but is there an advantage to > using Me.ControlName.Text over just using ControlName.Text? I have been
> leaving the Me. off but would include it if there are benefits.
>
> Thanks,
> Richard
>



Nov 21 '05 #9
"Richard Thornley" <rh**@thorsoft.com> schrieb:
I realize that this is a very basic question but is there
an advantage to using Me.ControlName.Text over just
using ControlName.Text? I have been leaving the Me.
off but would include it if there are benefits.


Consider this example:

\\\
Private Foo As Integer = 77

Private Function Test() As Integer
Dim Foo As Integer = 99
Return Me.Foo + Foo
End Function
///

;-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #10
It can be but you have to note that any method called using MyClass is taken
as Notoverridable as stated in MSDN below.

"
MyClass behaves like an object variable referring to the current instance of
a class as originally implemented. MyClass is similar to Me, but all method
calls on it are treated as if the method were NotOverridable. Therefore, the
method being called is not affected by overriding in a derived class.
"

HTH
rawCoder

"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:eH**************@TK2MSFTNGP09.phx.gbl...
Couldn't Me also be substituted for MyClass?
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Me is a handy reference if you cant remember the object name, intellisense
will give you a list.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
Hello,

I realize that this is a very basic question but is there an advantage

to using Me.ControlName.Text over just using ControlName.Text? I have been leaving the Me. off but would include it if there are benefits.

Thanks,
Richard



Nov 21 '05 #11
Hi Richard,

The Me keyword is actually required in some situations.

In the example class below, Me is used to disambiguate between Sub New's
lastName parameter and the LastName property. Since the Sub New parameter
is named 'lastName' and the class includes a Property named 'LastName', Me
is necessary to ensure the assignment works correctly. NOTE: If you don't
use Me in this case no error will be generated but assignements will not
always work as expected.

me.LastName = lastName

Public Class Customer
Private _LastName As String

Public Property LastName() As String
Get
Return _LastName
End Get
Set (ByVal value As String)
me._LastName = value
End Set
End Property

Public Sub New(ByVal lastName As String)
me.LastName = lastName
End Sub

Public Sub ChangeLastName(ByVal lastName As String)
me.LastName = lastName
End Sub

End Class

We have a policy at my development company - we always use the Me keyword.
Why?

1. There is no penalty for using Me.

2. Using Me triggers intellisense that reinforces an object-oriented style
of programming. Many authors and experts call Me (and the C# equivalent:
This) the OOP syntax for referring to class members.

3. As shown in the example above, Me is required in some cases.

4. Me improves code readability - one can always tell when a class member is
being used v.s. a local variable, parameter, etc.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
Hello,

I realize that this is a very basic question but is there an advantage to
using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.

Thanks,
Richard

Nov 21 '05 #12
Hi Mike,

Good Explanation,
Just a point.
Can we infer it as a kind of Scope Resolution Operator.

Thank You
rawCoder
"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:O$**************@tk2msftngp13.phx.gbl...
Hi Richard,

The Me keyword is actually required in some situations.

In the example class below, Me is used to disambiguate between Sub New's
lastName parameter and the LastName property. Since the Sub New parameter
is named 'lastName' and the class includes a Property named 'LastName', Me
is necessary to ensure the assignment works correctly. NOTE: If you don't use Me in this case no error will be generated but assignements will not
always work as expected.

me.LastName = lastName

Public Class Customer
Private _LastName As String

Public Property LastName() As String
Get
Return _LastName
End Get
Set (ByVal value As String)
me._LastName = value
End Set
End Property

Public Sub New(ByVal lastName As String)
me.LastName = lastName
End Sub

Public Sub ChangeLastName(ByVal lastName As String)
me.LastName = lastName
End Sub

End Class

We have a policy at my development company - we always use the Me keyword.
Why?

1. There is no penalty for using Me.

2. Using Me triggers intellisense that reinforces an object-oriented style
of programming. Many authors and experts call Me (and the C# equivalent:
This) the OOP syntax for referring to class members.

3. As shown in the example above, Me is required in some cases.

4. Me improves code readability - one can always tell when a class member is being used v.s. a local variable, parameter, etc.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
Hello,

I realize that this is a very basic question but is there an advantage to using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.

Thanks,
Richard


Nov 21 '05 #13
Mike,

Thanks for the indepth reply and to all the other replys that have been
made. I think I will start using Me. in my coding.

Richard

"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:O$**************@tk2msftngp13.phx.gbl...
Hi Richard,

The Me keyword is actually required in some situations.

In the example class below, Me is used to disambiguate between Sub New's
lastName parameter and the LastName property. Since the Sub New parameter
is named 'lastName' and the class includes a Property named 'LastName', Me
is necessary to ensure the assignment works correctly. NOTE: If you
don't use Me in this case no error will be generated but assignements will
not always work as expected.

me.LastName = lastName

Public Class Customer
Private _LastName As String

Public Property LastName() As String
Get
Return _LastName
End Get
Set (ByVal value As String)
me._LastName = value
End Set
End Property

Public Sub New(ByVal lastName As String)
me.LastName = lastName
End Sub

Public Sub ChangeLastName(ByVal lastName As String)
me.LastName = lastName
End Sub

End Class

We have a policy at my development company - we always use the Me keyword.
Why?

1. There is no penalty for using Me.

2. Using Me triggers intellisense that reinforces an object-oriented style
of programming. Many authors and experts call Me (and the C# equivalent:
This) the OOP syntax for referring to class members.

3. As shown in the example above, Me is required in some cases.

4. Me improves code readability - one can always tell when a class member
is being used v.s. a local variable, parameter, etc.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
Hello,

I realize that this is a very basic question but is there an advantage to
using Me.ControlName.Text over just using ControlName.Text? I have been
leaving the Me. off but would include it if there are benefits.

Thanks,
Richard


Nov 21 '05 #14
Not in the strictest sense; it does not qualify a namespace member to its
namespace the way a C++ scope resolution operator is used to qualify a
namespace member to its namespace.

The Me keyword refers to the current instance of the class and so all
members of the current instance can be referenced through it.

FYI the scope resolution operators for Microsoft programming languages:

Visual Basic Visual J# C++ C# JScript Visual FoxPro
Scope resolution
Scope resolution . n/a :: . and base n/a ::
--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"rawCoder" <ra******@hotmail.com> wrote in message
news:Ok**************@TK2MSFTNGP10.phx.gbl...
Hi Mike,

Good Explanation,
Just a point.
Can we infer it as a kind of Scope Resolution Operator.

Thank You
rawCoder
"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:O$**************@tk2msftngp13.phx.gbl...
Hi Richard,

The Me keyword is actually required in some situations.

In the example class below, Me is used to disambiguate between Sub New's
lastName parameter and the LastName property. Since the Sub New
parameter
is named 'lastName' and the class includes a Property named 'LastName',
Me
is necessary to ensure the assignment works correctly. NOTE: If you

don't
use Me in this case no error will be generated but assignements will not
always work as expected.

me.LastName = lastName

Public Class Customer
Private _LastName As String

Public Property LastName() As String
Get
Return _LastName
End Get
Set (ByVal value As String)
me._LastName = value
End Set
End Property

Public Sub New(ByVal lastName As String)
me.LastName = lastName
End Sub

Public Sub ChangeLastName(ByVal lastName As String)
me.LastName = lastName
End Sub

End Class

We have a policy at my development company - we always use the Me
keyword.
Why?

1. There is no penalty for using Me.

2. Using Me triggers intellisense that reinforces an object-oriented
style
of programming. Many authors and experts call Me (and the C# equivalent:
This) the OOP syntax for referring to class members.

3. As shown in the example above, Me is required in some cases.

4. Me improves code readability - one can always tell when a class member

is
being used v.s. a local variable, parameter, etc.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> I realize that this is a very basic question but is there an advantage to > using Me.ControlName.Text over just using ControlName.Text? I have been
> leaving the Me. off but would include it if there are benefits.
>
> Thanks,
> Richard
>



Nov 21 '05 #15

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

Similar topics

4
12488
by: Nuno | last post by:
Is there any SQL Error? Or I have to use Select case in VB code to control SQL instead. Thank you for any ans. Nuno
3
2108
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim...
1
6720
by: RC | last post by:
If I want to explicitly save the record before executing a Close action. Which of the following should I use? Or does it depend on whether it is based on a Form or something else? If Me.Dirty...
1
3064
by: RzB | last post by:
In a previous post in this NG (Oct 98) http://makeashorterlink.com/?D505347FB Henry Craven says that he was investigating a relationship between the presence or absence of a "Me!" prefix, the...
11
2454
by: Ayende Rahien | last post by:
I've a really strange problem, in some part of my code I compare two strings (through object), and while I *know* that they equal each other, and in the watch window they do equal each other, then...
5
1549
by: Agnes | last post by:
For my own practices. I like to put "Me". e.g IF Me.txtInvoice.textlength = 0 ....... etc Me.txt.....etc However, Is there any difference (without Me) ?? Thanks
6
1653
by: John | last post by:
Hi, Maybe someone can explain the use of "Me" to me? The example class CPoint3 uses the Me reference in the output statement: Console.WriteLine("CPoint3 constructor: {0}", Me) The text states:...
11
2119
by: comp.lang.php | last post by:
function blah($item) { if (!isset($baseDir)) { static $baseDir = ''; $baseDir = $item; print_r("baseDir = $baseDir\n"); } $dirID = opendir($item); while (($fyl = readdir($dirID)) !== false)...
1
2184
by: Ray | last post by:
Hello, Please help a VB newbie :) I'm a bit confused, reading all the MyClass, Me, My keywords of VB. I think I get MyClass and My, but Me... Can you just tell me if I get this correctly? ...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7271
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,...
1
6979
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...
0
7449
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...
0
5570
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,...
1
4998
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...
0
4666
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...
0
3160
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...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.