Now I will show how to do it.After reading this you will :
- Understand how to create class module
- how to use Let and get Property
Create Class Module
Click Class Module or in the project pane you can create new Class Module follow with figure 1.0
| Figure 1.0 : How to create Class Module |
![]() |
| Figure 1.1 : Use Project pane to create Class Module |
Option Compare Database
Option Explicit
Private m_id As String
Private m_name As String
Private m_age As Integer
Private m_phone As String
and next step we will provide user access all of private variables.. how to access it? Let's start with property
Create Let and Get Property
After we create private variables or attribute for your class you need to create a mechanism to read or write the value. let's start :
Click on Tab Insert --> Procedure
| Figure 1.2 Use the Add Procedure dialog box to create a new private or public property. |
you use the Get statement to read an object property from the internal private variable, and the Let statement to assign a value to the internal private variable. An object can have a number of variables, but you might only need to make a few of these available to the user.
Follow this code for create Property :
Public Property Get StudentId() As String
StudentId = m_id
End Property
Public Property Let setStudentId(ByVal myid As String)
m_id = myid
End Property
Public Property Get StudentName() As String
StudentName = m_name
End Property
Public Property Let setStudentName(ByVal myname As String)
m_name = myname
End Property
Public Property Get StudentAge() As Integer
StudentAge = m_age
End Property
Public Property Let setStudentAge(ByVal myage As String)
m_age = myage
End Property
So now let's start with our form test
Private Sub Command0_Click()
Dim stu As clsStudent
Set stu = New clsStudent
' Create Object stu from Class clsStudent
stu.setStudentId = "001"
stu.setStudentName = "Jonh Smith"
stu.setStudentAge = 52
MsgBox " ID = " & stu.StudentId & vbCrLf & "Name= " & stu.StudentName & vbCrLf & "Age = " & stu.StudentAge
End Sub
May 29, 2018
Tags :
ArticleDotNet
Subscribe by Email
Follow Updates Articles from This Blog via Email

No Comments