Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Creating External Libraries

Reply
 
Old 09-26-2008   #1 (permalink)
canes_venatici


 
 

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 SpecsSystem Spec
Old 09-26-2008   #2 (permalink)
ekkehard.horner


 
 

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
Have a look at

http://www.themssforum.com/VBscripts/VBScript-design/
My System SpecsSystem Spec
Old 09-27-2008   #3 (permalink)
canes_venatici


 
 

Re: Creating External Libraries

Thanks. That is perfect. I appreciate the help.

My System SpecsSystem Spec
Old 09-27-2008   #4 (permalink)
ekkehard.horner


 
 

Re: Creating External Libraries

canes_venatici schrieb:
Quote:

> Thanks. That is perfect. I appreciate the help.
>
You're welcome. If it's not to much time and effort,
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 SpecsSystem Spec
Old 10-22-2008   #5 (permalink)
gimme_this_gimme_that


 
 

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 SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Enterprise libraries .NET General
Icon libraries Vista General
functions libraries PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46