tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,926
- Office Version
- 365
- 2019
- Platform
- Windows
Simply looking at this code, it doesn't make sense:
' Standard module
'Class called Something
I didn't expect it to compile because my limited understanding of classes is that one must instantiate before using it.
Then I remembered about some additional settings that classes have, so I exported it, then opened it in notepad.
I think what made the code compile and run is this line:
Can someone please explain what it's doing and if setting it to be true means you don't have to instantiate, then why not set it to be true all the time?
Thanks
' Standard module
Code:
Sub Start()
Something.Test 1,2
End Sub
'Class called Something
Code:
Public Sub Test(Val1, Val2)
End Sub
I didn't expect it to compile because my limited understanding of classes is that one must instantiate before using it.
Then I remembered about some additional settings that classes have, so I exported it, then opened it in notepad.
Code:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Class1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public Sub Test(Val1, Val2)
End Sub
I think what made the code compile and run is this line:
Code:
Attribute VB_PredeclaredId = True
Can someone please explain what it's doing and if setting it to be true means you don't have to instantiate, then why not set it to be true all the time?
Thanks