RE: Calling functions in another .VBS

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Tom Lavedas (tlavedas_at_hotmail.remove.com)
Date: 08/27/04


Date: Fri, 27 Aug 2004 07:43:04 -0700

Assuming your project scripts are VBS files and that your 'library file' only
contains functions and subroutines, they can be included by reading them into
a string in the calling script and then passing the string to either an
Execute or an ExecuteGlobal statement, something like this ...

if Include("C:\path\LibIncludeScript.vbs") = 0 Then
  wsh.echo IncludeFunction("InputArgument")
else
  wsh.echo "Error"
End if

Function Include(sFileSpec)
  on Error Resume Next
  With CreateObject("Scripting.FileSystemObject")
    ExecuteGlobal .OpenTextFile(sFileSpec, 1).ReadAll
    Include = Err.Number
  End With
End Function

Be warned that the 'included' functions must be very robust (well tested and
with extensive error handling) as errors occurring within them are very hard
to diagnose when used this way.

Tom Lavedas
===========

"Ruchi Dayal" wrote:

> Hello:
>
> I have seen several messages when an include function helps in
> executing another .vbs.
>
> However, what I would like to do, is this:
>
> Make one "library" file which includes all common functions needed for
> a project. Then, from different .vbs scripts in the project, I should
> be able to call any function from this "library" file.
>
> Is this possible in .vbs ?
>
> Thanks,
>



Relevant Pages

  • RE: Calling functions in another .VBS
    ... Assuming your project scripts are VBS files and that your 'library file' only ... a string in the calling script and then passing the string to either an ...
    (microsoft.public.scripting.vbscript)
  • Re: Shortcut
    ... >sent via .VBS files. ... Everywhere you looked, 'Uninstall WSH!' ... I am going to do some research on creating .vbs scripts like ...
    (microsoft.public.excel.misc)
  • Re: creating a please wait message
    ... OK, I'll just call your scripts SIR scripts, as opposed to VBS scripts. ... Sub NewURL statement: ... though .vbs files can be imported and run through the program as ...
    (microsoft.public.scripting.vbscript)
  • Re: Adding two numbers does not work
    ... This is a syntax error that VBS will pick up, if there is no error handler. ... the type of error that Ray pointed out. ... data is delivered as a numeric string. ... but not if both are string subtypes. ...
    (microsoft.public.scripting.vbscript)
  • RE: Excel Worksheet Select (Activate ?) in VBS
    ... String" statement, since it gives me an error there. ... XLS file ontop of this vbs script, and it will display a list of all the ... Dim argsNamed, argsUnnamed ... set objWorkbooks = objExcelApp.Workbooks.Open) ...
    (microsoft.public.excel.programming)