Solved

Me?

Posted on 2002-06-07
13
156 Views
Last Modified: 2010-05-20
What is the Me Keyword? Please explain with the words: Objects and classes. Thank you, John
0
Comment
Question by:Round_Butte
  • 3
  • 3
  • 3
  • +2
13 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 7063372
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
 
LVL 22

Expert Comment

by:rspahitz
ID: 7063440
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
 
LVL 18

Expert Comment

by:mdougan
ID: 7063445
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
 

Author Comment

by:Round_Butte
ID: 7063609
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
 
LVL 22

Expert Comment

by:rspahitz
ID: 7063616
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
 
LVL 22

Expert Comment

by:rspahitz
ID: 7063617
>"its won width" is "its own width"
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 7063619
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
 
LVL 18

Expert Comment

by:mdougan
ID: 7063706
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
 

Author Comment

by:Round_Butte
ID: 7063827
emoreau :
So if I have a form named Inputform:
Me.name is equivelent to inputform.name?
John
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7064350
yes.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7064352
yes ... but from within the form.
0
 

Author Comment

by:Round_Butte
ID: 7064603
emoreau:
so as long as you are working within the open form, me is that form?
JOhn
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7067714
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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now