You are here: PSPad forum > English discussion forum > Re: In what sequence are VBScript files loaded?

Re: In what sequence are VBScript files loaded?

#1 In what sequence are VBScript files loaded?

Posted by: Professor Bernd | Date: 2020-10-10 23:47 | IP: IP Logged

Hello.

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?

Options: Reply | Quote | Up ^


#2 Re: In what sequence are VBScript files loaded?

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

Options: Reply | Quote | Up ^


#3 Re: In what sequence are VBScript files loaded?

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.

Options: Reply | Quote | Up ^


#4 Re: In what sequence are VBScript files loaded?

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?

Options: Reply | Quote | Up ^


#5 Re: In what sequence are VBScript files loaded?

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.

Options: Reply | Quote | Up ^


#6 Re: In what sequence are VBScript files loaded?

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. smiling smiley

Options: Reply | Quote | Up ^


#7 Re: In what sequence are VBScript files loaded?

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

Options: Reply | Quote | Up ^


#8 Re: In what sequence are VBScript files loaded?

Posted by: Professor Bernd | Date: 2020-10-11 19:34 | IP: IP Logged

Great. I look forward to it! smiling smiley

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR