Created
June 5, 2015 01:17
-
-
Save dck-jp/24daacc002d6b5c03f33 to your computer and use it in GitHub Desktop.
Using "Dim As New " cause lazy evaluation @ VBA
This file contains hidden or 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 | |
| Private Sub Class_Initialize() | |
| Debug.Print ("Xが初期化されたよー") | |
| End Sub | |
| Public Sub CookDoodleDo() | |
| Debug.Print ("こけっこっこー!") | |
| End Sub |
This file contains hidden or 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 | |
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test() と Test比較例() を走らせてみると
Dim As New を使うと、遅延初期化(遅延評価)されることが確認できます。