Most of guys will face this problem like,
- Having a class in a .vbs file say class1.vbs
- In another .vbs file, trying to create object for that class
Here it will say class is undefined because your class should be in global namespace so that your second script should know. To achieve this, use ExecuteGlobal command in VBScript.
Here I am putting sample function to include your class or other .vbs files which you are going to refer.
- Having a class in a .vbs file say class1.vbs
- In another .vbs file, trying to create object for that class
Here it will say class is undefined because your class should be in global namespace so that your second script should know. To achieve this, use ExecuteGlobal command in VBScript.
Here I am putting sample function to include your class or other .vbs files which you are going to refer.
- 'To include a file which are referenced here.
- Sub Include(file)
- Dim fso, f
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set f = fso.OpenTextFile(file, 1)
- str = f.ReadAll
- f.Close
- ExecuteGlobal str
- End Sub
- 'Just call this function like this in your scripts
- Call Include("C:\class1.vbs")
- 'Then try to create object for the above class
- Dim obj
- Set obj = New Class1
- 'continue...
Comments
Post a Comment