Me, My, MyBase, and MyClass in Visual Basic
Me, My, MyBase, and MyClass in Visual Basic have similar names, but different purposes. This topic describes each of these entities in order to distinguish them.
The Me keyword provides a way to refer to the specific instance of a class or structure in which the code is currently executing. Me behaves like either an object variable or a structure variable referring to the current instance. Using Me is particularly useful for passing information about the currently executing instance of a class or structure to a procedure in another class, structure, or module.
For example, suppose you have the following procedure in a module.
Sub ChangeFormColor(FormName As Form) Randomize() FormName.BackColor = Color.FromArgb(Rnd() * 256, Rnd() * 256, Rnd() * 256) End Sub
You can call this procedure and pass the current instance of the Form class as an argument by using the following statement.
The MyBase keyword behaves like an object variable referring to the base class of the current instance of a class. MyBase is commonly used to access base class members that are overridden or shadowed in a derived class. MyBase.New is used to explicitly call a base class constructor from a derived class constructor.