Call a Function in another VBScript?

Status
Not open for further replies.
Is there a way to call a Function inside a VBScript from another VBScript? We have VBScripts that automate certain tasks at my job, but if you ever need to change something, you have to change all of them which can be a pain. If I could call a Function that is inside another script, I could just keep one "Primary" script that I update and all of the other ones just call it.
 

upstateal

Ars Scholae Palatinae
1,013
Assuming you're talking about Windows Script Host scripts.

You will need to rearrange things a bit.

Collect all of your common functionality, constants, etc. into a single file. Then change your VBS files over to WSF files, and include the common file(s) into them.

See this page for starters

Or, since you're redoing a bunch of stuff here, take the opportunity to move them away from VBScript & into Powershell.
 

upstateal

Ars Scholae Palatinae
1,013
My VBScript is very rusty, so my syntax might be slightly off but this should illustrate the point.

Your main WSF file:
Code:
    <job>
<script src="commoncode.vbs"/>
      <script language="VBScript">
<![CDATA[
results = doStuff()
doMoreStuff(results)
]]>
        </script>
</job>
commoncode.vbs:
Code:
function doStuff()
    doStuff = "abc"
end function

function doMoreStuff(stringToUse)
   doMoreStuff = stringToUse + "123"
end function
 
Status
Not open for further replies.