Skip to content

Instantly share code, notes, and snippets.

@dck-jp
Created June 5, 2015 01:17
Show Gist options
  • Select an option

  • Save dck-jp/24daacc002d6b5c03f33 to your computer and use it in GitHub Desktop.

Select an option

Save dck-jp/24daacc002d6b5c03f33 to your computer and use it in GitHub Desktop.
Using "Dim As New " cause lazy evaluation @ VBA
Option Explicit
Private Sub Class_Initialize()
Debug.Print ("Xが初期化されたよー")
End Sub
Public Sub CookDoodleDo()
Debug.Print ("こけっこっこー!")
End Sub
Option Explicit
Sub Test()
Dim x As New Class1
Debug.Print ("Dim As New の次の行に移りました。")
x.CookDoodleDo
Debug.Print ("Test()は終了します。")
End Sub
Sub Test比較例()
Dim x: Set x = New Class1
Debug.Print ("Dim As New の次の行に移りました。")
x.CookDoodleDo
Debug.Print ("Test()は終了します。")
End Sub
@dck-jp
Copy link
Author

dck-jp commented Jun 5, 2015

Test() と Test比較例() を走らせてみると
Dim As New を使うと、遅延初期化(遅延評価)されることが確認できます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment