Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine path of script called via ExecuteGlobal 2

Status
Not open for further replies.

Frink

Programmer
Mar 16, 2001
798
GB
Hallo,

I have a script which I call from a parent script using ExecuteGlobal. Does anyone know how to get my child script to know which folder it is in as ScriptFullName returns the path to the parent script.

- Frink
 
Execute and ExecuteGlobal _copy_ the external code into the code that is currently running. So it is as if the external code were actually written in the current script.

If you want to execute the external code and have it be aware of it's location, you will have to call an objShell.Run method, which spawns a new process. The only problem is that if the external code needs variables from the current code, they won't be there.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Cheers, I thought that I was asking too much of VBS!
I have a common class which I can include in any script, however I want the common class to refer to another file in the same folder. If you see what I mean, but it looks like I'll have to use hard-coded paths in my scripts after all.
Here's my setup if you are interested:
AnyScript.vbs contains ExecuteGlobal of CommonClassLoader.vbs
CommonClassLoader.vbs checks for CommonClass object. If it doesn't exist then it performs ExecuteGlobal of CommonClass.vbs
CommonClass.vbs is a Class definition plus it defines and instantiates an object of CommonClass
AnyScript.vbs can then refer to methods of CommonClass via the instantiated object
Also, AnotherScript.vbs (which contains ExecuteGlobal of CommonClassLoader.vbs) can do an ExecuteGlobal of AnyScript.vbs and the class won't be instantiated twice.

It works well, except for the annoyance of having to specify a hard-coded path in the ExecuteGlobal of CommonClass and CommonClassLoader.
I can't see any way around this as I don't want to change the current directory.

Cheers for the info anyway,

- Frink
 
You are not asking too much of vbs; you just not ask clear enough.

In the statement like
[tt] executeglobal <expression>[/tt]
not only what done in the expression would be made available to the "parent", what avail in "parent" is also stand-ready for the expression to use.

When you load up classloader.vbs, you supply, do you not, the directory to it, say, 'd:\class_container" for instance. Hence that piece of information is know.

[1] In the "parent", set up a variable.
[tt]
dim sdir_container
sdir_container="d:\class_container"
[/tt]
[2] In the classloader.vbs, you can set up the same variable. And when you need to load commonclass, you check the variable if it is empty. If not, use it.
[tt]
dim sdir_container
'etc etc
if not isempty(sdir_container) then
'use it to point to commonclass: it will be in the same directory of the classloader.vbs itself.
else
'use currentdirectory of the "parent" or some other alternative
end if
[/tt]
Then, it is done.
 
Cheers tsuji,
What you wrote got me thinking, and I defined a constant in AnyScript and AnotherScript (with handling to ignore any errors for multiple defines) which points to the CommonClassLoader location. Then my ExecuteGlobal uses that path.
CommonClassLoader can also use it to get to CommonClass.

- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top