Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

VBAでメソッドチェーンの例

View CCalc.cls
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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
View CCalc.cls
1 2 3 4 5 6 7 8 9
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
Something went wrong with that request. Please try again.