Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Add a class function

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,29285
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Add a class function
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Add a class function - 12/23/2005 3:20:37 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
This is a function that will add a class from an external file. It is as close to a #include that I have been able to come up with in VBScript. The class that you want to add needs to be saved in a file and must be valid vbscript. Here is an example of its use (the example assumes that there is a valid class file in the same directory as the test code is running in and that the valid class file is named LoggerClass.vbs):

Option Explicit

Dim arrReturn

'This is an example of trying to load a class from a file that does not exist. This will fail.
arrReturn = AddClass("Fail.vbs")
WScript.Echo "Fail: " & arrReturn(0) & " - " & arrReturn(1)
'This line will load a class from the file LoggerClass.vbs as long as that file is present
arrReturn = AddClass("LoggerClass.vbs")
WScript.Echo "Success: " & arrReturn(0) & " - " & arrReturn(1)

This test code should produce this output:
Fail: 1 - The specified class file Fail.vbs does not exist
Success: 0 -


Here is the actual function:

      


EDIT: Added comments

< Message edited by ebgreen -- 1/4/2006 3:27:38 AM >


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm
 
 
Revisions: 1 | Post #: 1
 
 RE: Add a class function - 12/23/2005 1:39:18 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
could you please explain this in more detail or comment your code?


Thanks!

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ebgreen)
 
 
Post #: 2
 
 RE: Add a class function - 1/4/2006 3:28:20 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I added some comments. If it is still not clear enouh, let me know and I will explain further.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to kirrilian)
 
 
Post #: 3
 
 RE: Add a class function - 1/4/2006 3:40:03 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
so the executeglobal allows you to load code, but couldnt you just use any text file?
eg. myClasses.inc rather than myClasses.vbs

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ebgreen)
 
 
Post #: 4
 
 RE: Add a class function - 1/4/2006 3:44:12 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Yes you could use any file that is a text file containing valid VBScript code.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to kirrilian)
 
 
Post #: 5
 
 RE: Add a class function - 1/4/2006 4:05:33 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
excellent, now i can REALLY obfuscate my code

talk about job security!

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: Add a class function - 1/4/2006 4:18:30 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
We use it to put a folder on all desktop machines that is in the path and has .vbs files containing all of our commonly used classes.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to kirrilian)
 
 
Post #: 7
 
 RE: Add a class function - 1/4/2006 4:18:39 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
ive just verified that you can load the code from any text file, very useful!

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to kirrilian)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Add a class function Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts