Al
Sun Jul 24 11:36:07 CDT 2005
"Craig Bender" <cbender@pxpert.com> wrote in message
news:e%237QyyojFHA.4000@TK2MSFTNGP12.phx.gbl...
> I can't believe this is so complicated!
Believe it.
> Even with my junior program skills
> I know this a basic necessity to be able code, otherwise you are
constantly
> coping and pasting your needed functions back and forth. In perl and I
> believe java and most other languages this is just a one liner to Include
> another file at the top of your script.
Each language and platform has its own approaches - expecting them all to be
of the same flavour will lead only to frustration.
> And as far as the worry of
> duplicate variable names I would assume you could just state Private for
> each sub and funtion?
"Private" variables are only private within classes. Regardless, I use
"private" to declare a global variable that needs to be persistent, and my
naming convention is that its name starts with the name of the function it
"belongs to:.
> I guess out of all your suggestions, example #1 is the way I would go.
I disagree, but ymmv. Example 1 requires each script to have its own copy of
an "include" function - there's that cutting and pasting that neither of us
likes. It also requires your script to manage the location of the library
files, and to include some sort of generic exception handling in the event
the files are not accessible. Finally, the cons listed are those that make
it difficult to fully debug library routines.
> Suggestion #3 is seems way to complicated and I'm not sure it gives me the
> flexibility of just drafting a quick script and including myfunc script
with
> it.
There I tend to agree with you, but there are others here who swear by (not
at) it. ;-)
> And suggestion #2 also doesn't seem flexible.
That depends on how you work it. I find it "flexible" enough that I use it
(almost) all of the time. Having a reasonably well debugged set of ready to
use library routines results in less adhoc scripting and a more consistently
structured approach. It's not perfect, mind, and there are changes I would
like (but do not expect) to see.
It also helps to work with a .WSF-aware scripting editor (like PrimalScript)
so that one need not spend much time dealing with the XML details.
> I think it would be
> perfect if I can have a "myfuncs.wsc" and then just somehow reference that
> in my VBS scripts. As I want to be able to write a VBS script and just
> reference a file so that I can call functions that are held in that file.
Hey, I'd like it if vbs/wsh were converted to a compiled language complete
with a function library functionality, but it ain't gonna happen.
But I think that the .wsf format comes the closest to allowing you to write
code that is ONLY associated with the CALLING of library functions, and NOT
the management of the library itself.
> One last example being I have a function called WriteLog(), which I copy
and
> paste everything I write a new script. Instead I should be able to just
> copy and paste my header (that references/includes this myfuncs script)
and
> be able to just call WriteLog in my script.
You are pre-supposing the best solution to be one that is not available,
even though it is in other platforms. .WSF does this for me, however, I
don't cut-and-paste anything - I just start a new project and include the
library files I need with script tags once, and forget it. Even easier, when
editing the code itself, I do not even see references to these files in
headers in the code - they are "hidden" in the XML code.
/Al
>
> Thanks,
> Craig.
>
>
> "Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
> news:uA7nwahjFHA.3540@TK2MSFTNGP14.phx.gbl...
> > Craig Bender wrote:
> >
> >> Simple question, as I build up my little library of some useful
functions
> >> I want to keep all of these in a "myfuncs.vbs" script. Then when I
write
> >> a quick new script I just want to be able to call funtions located in
> >> "myfuncs.vbs". How do I do this?
> >>
> >> Thanks for your help in advance!
> > Hi,
> >
> > For different methods and some examples of code libraries and their
> > pros and cons, you can take a look here:
> >
> >
http://groups.google.co.uk/group/microsoft.public.scripting.vbscript/msg/6898681c85413286?dmode=source&hl=en
> >
> >
> > Some interesting WSC links for future use maybe:
> >
> > Windows Scripting Components - An Introduction
> >
http://www.aspfree.com/c/a/Windows-Scripting/Windows-Scripting-Components--An-Introduction/
> >
> >
> >
> > How to generate a WSC type library file automatically:
> >
http://groups.google.co.uk/groups?selm=3EBD6A07.C56E6B71%40hydro.com
> >
> > Optional methods to reference the WSC that is not registered from
> > a script:
> >
http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=uKQPMyT1BHA.2736%40tkmsftngp03
> >
> >
> > --
> > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> > Administration scripting examples and an ONLINE version of
> > the 1328 page Scripting Guide:
> >
http://www.microsoft.com/technet/scriptcenter/default.mspx
>
>