Skip to content

Instantly share code, notes, and snippets.

@honda0510
Created March 2, 2012 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save honda0510/1956111 to your computer and use it in GitHub Desktop.
Save honda0510/1956111 to your computer and use it in GitHub Desktop.
VBAでメソッドチェーンの例
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
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