Besides this global instance, it is possible to create additional instances of this class.
predeclared.cls
This is the source code of the class whose attribute vb_predeclaredId
is set to true
:
attribute vb_predeclaredId = true
option explicit
private member as long
sub class_initialize()
debug.print "An instance of predeclared is being initialized"
end sub
sub class_terminate()
debug.print "terminate predeclared instance, member = " & member
end sub
sub setMemberValue(m as long) ' {
debug.print "setting member value to " & m
member = m
end sub ' }
function getMemberValue() as long' {
getMemberValue = member
end function ' }
func.vb
This
module accesses the global instance and creates an additional one, named
abc
:
option explicit
sub main() ' {
predeclared.setMemberValue 42
dim abc as new predeclared
abc.setMemberValue 99
debug.print "member value of predeclared is: " & predeclared.getMemberValue
debug.print "member value of abc is: " & abc.getMemberValue
end sub ' }
Creating the project
<job>
<script language="VBScript" src="../../VBS-MS-Office-App-Creator/create-MS-Office-app.vbs" />
<script language="VBScript">
option explicit
dim app
dim xls
set xls = createOfficeApp("excel", currentDir() & "created.xlsm")
if xls is nothing then ' {
wscript.echo("Could not create excel worksheet.")
wscript.quit(-1)
end if ' }
set app = xls.application
insertModule app, currentDir() & "func.vb" , "func" , 1
insertModule app, currentDir() & "predeclared.cls", "predeclared", 2
'
' Show VB editor
'
app.VBE.mainWindow.visible = true
xls.save
app.run "main"
createObject("WScript.Shell").appActivate(app.caption)
</script></job>
On the command line, it must be invoked with
P:\ath\to\project> cscript .\create.wsf