Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Classes/VBA/classes-1.vba
Normal file
31
Task/Classes/VBA/classes-1.vba
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
Private Const m_default = 10
|
||||
Private m_bar As Integer
|
||||
|
||||
Private Sub Class_Initialize()
|
||||
'constructor, can be used to set default values
|
||||
m_bar = m_default
|
||||
End Sub
|
||||
|
||||
Private Sub Class_Terminate()
|
||||
'destructor, can be used to do some cleaning up
|
||||
'here we just print a message
|
||||
Debug.Print "---object destroyed---"
|
||||
End Sub
|
||||
Property Let Bar(value As Integer)
|
||||
m_bar = value
|
||||
End Property
|
||||
|
||||
Property Get Bar() As Integer
|
||||
Bar = m_bar
|
||||
End Property
|
||||
|
||||
Function DoubleBar()
|
||||
m_bar = m_bar * 2
|
||||
End Function
|
||||
|
||||
Function MultiplyBar(x As Integer)
|
||||
'another method
|
||||
MultiplyBar = m_bar * x
|
||||
'Note: instead of using the instance variable m_bar we could refer to the Bar property of this object using the special word "Me":
|
||||
' MultiplyBar = Me.Bar * x
|
||||
End Function
|
||||
37
Task/Classes/VBA/classes-2.vba
Normal file
37
Task/Classes/VBA/classes-2.vba
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
Public Sub foodemo()
|
||||
'declare and create separately
|
||||
Dim f As Foo
|
||||
Dim f0 As Foo
|
||||
|
||||
Set f = New Foo
|
||||
|
||||
'set property
|
||||
f.Bar = 25
|
||||
'call method
|
||||
f.DoubleBar
|
||||
'alternative
|
||||
Call f.DoubleBar
|
||||
Debug.Print "f.Bar is "; f.Bar
|
||||
Debug.Print "Five times f.Bar is "; f.MultiplyBar(5)
|
||||
|
||||
'declare and create at the same time
|
||||
Dim f2 As New Foo
|
||||
Debug.Print "f2.Bar is "; f2.Bar 'prints default value
|
||||
|
||||
'destroy an object
|
||||
Set f = Nothing
|
||||
|
||||
'create an object or not, depending on a random number:
|
||||
If Rnd() < 0.5 Then
|
||||
Set f0 = New Foo
|
||||
End If
|
||||
'check if object actually exists
|
||||
If f0 Is Nothing Then
|
||||
Debug.Print "object f0 does not exist"
|
||||
Else
|
||||
Debug.Print "object f0 was created"
|
||||
End If
|
||||
'at the end of execution all remaining objects created in this sub will be released.
|
||||
'this will trigger one or two "object destroyed" messages
|
||||
'depending on whether f0 was created...
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue