Posted by: Professor Bernd | Date: 2020-10-10 23:47 | IP: IP Logged
Assuming there are several VBScripts: _Script_1.vbs, _Script__B.vbs, AScript.vbs, 123.vbs and MyFuncs.vbs. In MyFuncs.vbs there is for example a function "Foo(s_Var1)". To use Foo() in several VBScripts, I can call 'MyFuncs.Foo("Hello World!")' in these scripts.
But if I call Foo() in the "init" routine from these scripts, e.g. to read paths, then in one script I get an error message because MyFuncs.vbs is not loaded yet and in another script everything works fine.
How can I make sure that a script is loaded as first file before all other files?
Posted by: pspad | Date: 2020-10-11 05:58 | IP: IP Logged
I don't know it just now, but I guess they are processed alphabetically. Try name your module with functions to be before others
Posted by: Professor Bernd | Date: 2020-10-11 06:15 | IP: IP Logged
It seems that the underscores "_" confuse the sorting. In Windows Explorer the sorting is different than e.g. in a Zip archive opened in 7-Zip. I'm trying to rename the modules so that a specific module is loaded first.
Are JScripts loaded before VBScripts? Then maybe this could be a way to make sure that a certain module is loaded before the others.
Posted by: Professor Bernd | Date: 2020-10-11 14:37 | IP: IP Logged
It seems like you can't be sure which module is actually loaded first. You cannot rely on a specific sort order. For stable editor extensions all needed routines have to be inserted in each module. This is currently about 400 lines extra for each module and it makes my code confusing.
Could you include a routine that loads a given script first?
I suppose that you load all script modules in a loop. You could load the given file (for example "Main.vbs") before the loop is executed. Pseudo code:
If FileExists("Main.vbs") Then Load("Main.vbs")
In the loop it is possible to filter so that the "Main.vbs" is not loaded twice:
If Not FileName = "Main.vbs" Then ...
What do you think, is this possible or is it too much effort?
Posted by: pspad | Date: 2020-10-11 14:44 | IP: IP Logged
I must take a look how modules are loaded. I guess there is FindFirs / FindNext used to go through folder files and what is found is send to module for compile.
I can add step to load it into list, sort it and send to scripting. If you will name your file as _Main.vbs, you can be sure then that is loaded as first.
Posted by: Professor Bernd | Date: 2020-10-11 15:10 | IP: IP Logged
That sounds very good! Choose the option that is easiest for you. I am happy if it works.
Posted by: pspad | Date: 2020-10-11 18:08 | IP: IP Logged
Sorting scripts before adding to script engine feature was added. Available in next build
Posted by: Professor Bernd | Date: 2020-10-11 19:34 | IP: IP Logged
Great. I look forward to it!