469,290 Members | 1,804 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

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 10274
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Ayende Rahien | last post: by
6 posts views Thread by John | last post: by
11 posts views Thread by comp.lang.php | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.