![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Creating External Libraries I'm looking to create my own classes for use in my internal scripts. I can't find any good documentation so I thought I would ask here... Lets say i want to create class Foo with a few properties and methods... I create the class and the properties and methods... and save that to a file. foo.vbs Now, in my production script bar.vbs how do i reference the classes in foo.vbs? Or is this even possible? set oBar = CreateObject("Foo.Foo") ???? Anybody have any thoughts? many thanks. Austin |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Creating External Libraries canes_venatici schrieb: Quote: > I'm looking to create my own classes for use in my internal scripts. > I can't find any good documentation so I thought I would ask here... > > Lets say i want to create class Foo with a few properties and > methods... > > I create the class and the properties and methods... and save that to > a file. foo.vbs > > Now, in my production script bar.vbs how do i reference the classes > in foo.vbs? Or is this even possible? > > set oBar = CreateObject("Foo.Foo") ???? > > Anybody have any thoughts? many thanks. > > > Austin http://www.themssforum.com/VBscripts/VBScript-design/ |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Creating External Libraries Thanks. That is perfect. I appreciate the help. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Creating External Libraries canes_venatici schrieb: Quote: > Thanks. That is perfect. I appreciate the help. > I'd appreciate to learn, which of the different methods you decide to use. Of course I'd be grateful for other people's opinion/experience too. I use the ExecuteGlobal strategy for my libraries, but consider switching to a .WSC/script: approach. Thanks |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Creating External Libraries I think this is what you are looking for ... Class User Private m_sAMAccountName Public Property Let sAMAccountName(p_sAMAccountName) m_sAMAccountName = p_sAMAccountName end Property Public Property Get sAMAccountName() sAMAccountName = m_sAMAccountName End Property Public Sub CalculateTotals MsgBox "In Calculate Totals" End Sub End Class Set usr = New User usr.sAMAccountName = "John Doe" usr.CalculateTotals --- Classes can be useful. In a multi-developer environment no one over writes someone else's code. Also - it makes for a more natural flow, say if you're converting back and forth from VBA Modules. It's a good idea to use class objects if you're looping and inserting. That way, if you have a "Resume On Next" statement you're certain not to persist data on the current iteration that came from the previous iteration - because on each iteration you start with a fresh new class object to manipulate. You can include classes in your VBScripts scripts like this: Sub Include(sInstFile) Set oFSO = CreateObject("Scripting.FileSystemObject") Set f = oFSO.OpenTextFile(GetPath() & sInstFile) s = f.ReadAll f.Close ExecuteGlobal s End Sub Include "SomeVBScriptClass.vbs" This syntax works in HTA VBScript too - so you can include WScript in your VBScript if you swap out an HTML file with an HTA file. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Enterprise libraries | .NET General | |||
| Icon libraries | Vista General | |||
| functions libraries | PowerShell | |||