Skip to content

Instantly share code, notes, and snippets.

@yu-tang
Last active December 22, 2015 12:28
Show Gist options
  • Save yu-tang/6472501 to your computer and use it in GitHub Desktop.
Save yu-tang/6472501 to your computer and use it in GitHub Desktop.

以下のコードに示す Main プロシージャの実行結果(イミディエイト出力)を答えよ。

''' Class Module: MyService.cls
Option Explicit

Private Sub Class_Initialize()
    Debug.Print "「いらっしゃいませ」(Initialize)"
    Debug.Print "「ご利用を開始します。終了時に所定の手数料を引き落とします」"
End Sub

Private Sub Class_Terminate()
    Debug.Print "「★★★所定の手数料を引き落とします★★★」"
    Debug.Print "「ご利用ありがとうございました」(Terminate)"
End Sub

Public Function Use() As String
    Use = TypeName(Me) & " is used."
End Function
''' Standard Module: MyModule.bas
Option Explicit

Private Sub Avail(service As MyService)
    Debug.Print
    If service Is Nothing Then
        Debug.Print "check : service NOT available."
    Else
        Debug.Print "check : service available."
        Debug.Print service.Use
    End If
End Sub

Private Sub Proc1()
    Debug.Print "--(利用開始)--"
    
    Dim service As MyService
    Set service = New MyService
    
    Avail service
    Set service = Nothing
    Debug.Print "--(ここでは一回で利用終了)--"

    ' some operations...

    Avail service
    Debug.Print "----"

    ' more operations...

    Avail service
    Debug.Print "----"

End Sub

Private Sub Proc2()
    Debug.Print "--(利用開始)--"
    
    Dim service As New MyService
    
    Avail service
    Set service = Nothing
    Debug.Print "--(ここでは一回で利用終了)--"

    ' some operations...

    Avail service
    Debug.Print "----"

    ' more operations...

    Avail service
    Debug.Print "----"

End Sub

Public Sub Main()
    Debug.Print "** Proc1()"
    Call Proc1
    
    Debug.Print
    Debug.Print "** Proc2()"
    Call Proc2
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment