Created
March 2, 2012 06:03
-
-
Save honda0510/1956111 to your computer and use it in GitHub Desktop.
VBAでメソッドチェーンの例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
' クラスモジュール: CCalc | |
Private sum As Long | |
Private Sub Class_Initialize() | |
sum = 0 | |
End Sub | |
Public Function plus(num As Long) As CCalc | |
sum = sum + num | |
Set plus = Me | |
End Function | |
Public Function minus(num As Long) As CCalc | |
sum = sum - num | |
Set minus = Me | |
End Function | |
Public Function show() As Long | |
show = sum | |
End Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
' 標準モジュール: Module1 | |
Sub test() | |
Dim calc As CCalc | |
Set calc = New CCalc | |
MsgBox calc.plus(10).minus(3).show ' 7 | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment