Advertisement
3_2004-2005 Object Oriented Programming (OOP) #137505

Classes In VBScript

This code will allow you to use classes in VBSccript versions 5.0 and higher

AI

Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Codice sorgente
original-source
'Class C
Class C
 'Method F
 Sub F(msg)
 MsgBox msg
 End Sub
End Class
'Using the class C
Sub Main()
 Dim o
 Set o = New C
 
 o.f "my message!"
 'wow a MsgBox will appear
End Sub
'another example
Class cEmployee
 'local variables to hold property values
 Private mvarFullName 'local copy
 Private mvarAge 'local copy
 Private mvarRank 'local copy
 Private mvarSalary 'local copy
 
 Public Property Let Salary(ByVal vData)
 'used when assigning a value to the property, on the left side of an assignment.
 mvarSalary = vData
 End Property
 
 Public Property Get Salary()
 'used when retrieving value of a property, on the right side of an assignment.
 Salary = mvarSalary
 End Property

 Public Property Let Rank(ByVal vData)
 'used when assigning a value to the property, on the left side of an assignment.
 mvarRank = vData
 End Property
 
 Public Property Get Rank()
 'used when retrieving value of a property, on the right side of an assignment.
 Rank = mvarRank
 End Property
 

 Public Property Let Age(ByVal vData)
 'used when assigning a value to the property, on the left side of an assignment.
 mvarAge = vData
 End Property
 Public Property Get Age()
 'used when retrieving value of a property, on the right side of an assignment.
 Age = mvarAge
 End Property

 Public Property Let FullName(ByVal vData)
 'used when assigning a value to the property, on the left side of an assignment.
 mvarFullName = vData
 End Property
 Public Property Get FullName()
 'used when retrieving value of a property, on the right side of an assignment.
 FullName = mvarFullName
 End Property
End Class

Sub Main()
 dim o
 set o = new cemployee
 o.fullname="Alex Karpman"
 o.age=13
 o.salary=1000000
 o.rank="Big Boss"
 
 msgbox o.fullname
 msgbox o.age
 msgbox o.salary
 msgbox o.rank
 msgbox o.fullname & "-" & o.age & "-" & o.salary & "-" & o.rank
end sub
Commenti originali (3)
Recuperato da Wayback Machine