'AIM : PROGRAM TO IMPLEMENT CLASS MODULES IN VISUAL BASIC
'NAME : JEKIN . J . TRIVEDI
'CLASS : SE - IT(B5) ROLL NO : 67
'*************************CODE FOR STUDENT CLASS MODULE ****************
Private m_studentid As String
Private m_firstname As String
Private m_lastname As String
Private m_majorcode As String
Private m_yearlevel As String
Private m_birthdate As Date
Property Get StudentID() As String
StudentID = m_studentid
End Property
Property Let StudentID(ByVal strnewvalue As String)
'Raise an error if an invalid assignment is attempted
If Len(strnewvalue) = 0 Then Err.Raise 5 'Ivalid procedure
'argument else stored in the private member variable
m_studentid = strnewvalue
End Property
Property Get firstname() As String
firstname = m_firstname
End Property
Property Let firstname(ByVal strnewvalue As String)
'raise an error if an inalid assignment is attempted
If Len(strnewvalue) = 0 Then Err.Raise 5 'invalid procedure argument
'else store in the private member variable
m_firstname = strnewvalue
End Property
Property Get lastname() As String
lastname = m_lastname
End Property
Property Let lastname(ByVal strnewvalue As String)
'raise an error if an inalid assignment is attempted
If Len(strnewvalue) = 0 Then Err.Raise 5 'invalid procedure argument
'else store in the private member variabel
m_lastname = strnewvalue
End Property
Property Get Majorcode() As String
Majorcode = m_majorcode
End Property
Property Let Majorcode(ByVal strnewvalue As String)
If Len(strnewvalue) = 0 Or Len(strnewvalue) > 1 Then Err.Raise 5
'End If
m_majorcode = strnewvalue
End Property
Property Get yearlevel() As String
yearlevel = m_yearlevel
End Property
Property Let yearlevel(ByVal strnewvalue As String)
Dim vartemp As Variant
Dim found As Boolean
For Each vartemp In Array("Freshman", "sophomore", "Junior", "Senior")
If InStr(1, strnewvalue, vartemp, vbTextCompare) Then
found = True
Exit For
End If
Next
If Not found Then Err.Raise 5
m_yearlevel = strnewvalue
End Property
Property Get birthdate() As Date
birthdate = m_birthdate
End Property
Property Let birthdate(ByVal datnewvalue As Date)
If datnewvalue >= Now Then Err.Raise 1001, , "Future Date!"
m_birthdate = datnewvalue
End Property
'*************************CODE FOR FORM1 ****************
'Declare object of student class
Dim ostudent As Student
Private Sub Command1_Click()
Set ostudent = New Student
'Use the object student
ostudent.StudentID = "990680"
ostudent.firstname = "Dhiraj"
ostudent.lastname = "Vanmali"
ostudent.Majorcode = "A"
ostudent.yearlevel = "Senior"
ostudent.birthdate = "19-9-2008"
Print "Student ID :" & ostudent.StudentID & vbCrLf
Print "First Name :" & ostudent.firstname & vbCrLf
Print "Last Name :" & ostudent.lastname & vbCrLf
Print "Major Code:" & ostudent.Majorcode & vbCrLf
Print "Year: " & ostudent.yearlevel & vbCrLf
Print "Date of Birth:" & ostudent.birthdate
Set ostudent = Nothing
End Sub
No comments:
Post a Comment