Introduction to Classes and Objects - learnit

Home Top Ad

Post Top Ad

Sunday, May 23, 2021

Introduction to Classes and Objects

Introduction to Classes and Objects

Introduction to Classes and Objects

Introduction

A class is a technique of using one variable or a group of variables in one unit to describe an object.

Creating a Class

To help you create a class, Microsoft Visual Basic provides a special version of a module named a class module. To create a class

1)In Microsoft Access, on the Ribbon, click Create. In the Macros and Code section, click the Class Module button

2)In Microsoft Visual Basic:

      On the main menu, click Insert and click Class Module

      On the Standard toolbar, click the arrow of the Insert Module button and click Class Module

As mentioned for the regular module, Microsoft Visual Basic would give a default name to the module. Normally, you should name the module based on the name you want for your class. To name or re-name a class module, click its name in the Project window. In the Properties window, click (Name) or its text box. Type the desired name and press Enter. After creating and naming the module, it becomes a class.


The Contents, Body, and Members of a Class

The whole area of a class module, that is, the whole content of the file is referred to as the body of the class. All things in the module, that is, all the object inside the document are (considered as) the members of the class.


The Member Variables of a Class

A class is a combination of values or variables. To create those values or variables, declare each variable in the module.

Practical Learning: Adding Members to a Class


Option Compare Database
Option Explicit
Public id as Integer
Public Name as String
Public Salary As Integer


Create an Object

Introduction

After creating a class, to use it in your project, you must declare a variable for it. This is also referred to as creating an object or creating an instance of the class. To create an object, use the Dim keyword followed by a name for the object, the As keyword, and the name of the class.


Private Sub Command0_Click()
Dim customer1 as Class1
End Sub


Allocating Computer Memory for an Object

To let the computer hold the values of an object, you must allocate some computer memory for it. To assist you with this, the Visual Basic language provides an operator named New. To use it, assign it to the variable and follow it with the name of the class


Prviate Sub Command0_Click()
Dim Customer1 as Class1
Set Customer1=New Class1
End Sub

Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad