Me?

What is the Me Keyword? Please explain with the words: Objects and classes. Thank you, John
Round_ButteAsked:
Who is Participating?
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
me is the current instance of an object.


for example, if in the Form_load event of a form you type:

Me.Caption = "Something"

it is equivalent to :

YourFormName.Caption = "Something"
0
 
rspahitzCommented:
Is this homework?

Me represents the current class instance, referred to in other languages as "this".

From MS help:

"When a class can have more than one instance, Me provides a way to refer to the specific instance of the class where the code is executing. Using Me is particularly useful for passing information about the currently executing instance of a class to a procedure in another module."
0
 
mdouganCommented:
yea, what he said....

you can think of it like this, if the code that you are looking at is inside of an object such as a form or a class, then when the code executes, it will be refering to the instance of that object that is currently executing.  

So, if a form called Form1 had a public function called SetBackgroundColor, and inside of that function there was some code like:

Me.BackColor = RGB(255,0,0)


Then, if in someother form, you had code such as:

Load Form1
Form1.SetBackgroundColor

Then the Me in that function would be refering to Form1 (or you could say the Form1 instance of Form1)

However, if you had this code in some other form:

Dim x as New Form1

x.SetBackgroundColor

Then the Me in that function would be refering to X which is an instance of Form1.

It's similar in concept to the This operator in C++ (or is that Java)

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Round_ButteAuthor Commented:
No this is not homework, I am a newbie and am trying to learn what it means and please now explain without the words objects and classes.  

Now explain a class and a object!
John
0
 
rspahitzCommented:
Note: your original comment asked to explain WITH classes.

Here goes:

A class is a definition of something...in essence, a blueprint.
An object instance is the creation made from that class' blueprint.

Once you have made the object, it can refer to another part of itself by using the "me" keyword.

So, a form class defines how to make a form.
An instance of a form is an object that was built using those instructions.

Within the form object that was just created, you can use "Me" to refer to anything within that form such as "Unload Me" or "Me.Width" to tell the object to unload itself or to get its won width, respetively.
0
 
rspahitzCommented:
>"its won width" is "its own width"
0
 
Arthur_WoodCommented:
when you have code that is writen in a Form, then ME referes to THAT form.

An object is ANYTHING that your program can work with - A form, for instance, is an Object.  A Control is an Object.

A Class is the "Recipe" for an Object - It is the code which describes what the "thing" is capable of doing, what it will be like, when it is created.

Just as a RECIPE for Chocolate Chip Cookies tells the cook HOW TO MAKE a Chocolate Chip Cookie (but the RECIPE itself IS NOT a Chocolate Chip Cookie), so too a Class is the instructions, to the program, of HOW TO MAKE an Object (called an INSTANCE in Object-Oriented (OO) Speak)) of the type described by the class, but the Class IS NOT the Object made from that Class.

If you have ANY serious plans to learn VB at all, then you better learn about Objects and Classes VERY VERY VERY (got the idea of how significant these two concepts are?) VERY quickly.  Otherwise, you will just be playing around with VB, and my advice to you, in that case, would be to forget it, and got play outside in the sandbox.  I am a proferssional VB developer, and Objects and classes are the most FUNDAMENTAL concept underlying Visual Basic (especially VB.NET - the newest version of VB).  I cannot strees that strongly enough.

Arthur Wood
0
 
mdouganCommented:
You can think of a Class as a template.  By itself, it is just a blueprint for what you can do.  They are generally designed to "implement" some business entity.  They can have a data element, meaning that it has some variables declared inside of them, and they can have a code element, some functions that can be called.

When you create an instance of a class, this is generally considered an object.

As an example, let's say that you have a Class that is designed to act like a person's Checking Account.  It might have a data element called Balance, and it might have a couple of functions such as MakeADeposit, MakeAWithdrawal.

In an application, let's say it's an automatic teller application, then when the user logs in (enters their pin information), then the program might create an instance of the Checking Account class, and then this object instance loads the balance of the user who logged in.  And, when the user makes a withdrawal, the object instance executes the procedure and takes money out of the user's account.

So, the class can be used to access any number of checking accounts.  However, when an object instance is created, it is created to access a particular account.
0
 
Round_ButteAuthor Commented:
emoreau :
So if I have a form named Inputform:
Me.name is equivelent to inputform.name?
John
0
 
Éric MoreauSenior .Net ConsultantCommented:
yes.
0
 
Éric MoreauSenior .Net ConsultantCommented:
yes ... but from within the form.
0
 
Round_ButteAuthor Commented:
emoreau:
so as long as you are working within the open form, me is that form?
JOhn
0
 
mdouganCommented:
Like I said though, if you create a "New" form based on the type of another form, then the Me only refers to that instance:

Dim x as New Form1

x.SetBackgroundColor

Then inside of that SetBackgroundColor function a reference to Me.Name is not equivelent to Form1.name, it is equivelent to x.Name
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.