|
|
|||||||
Hello! My login-script is starting to be confusing, so I start to swap parts of it in own script that I run with form the main-script with the call-command. But in the main-script are some UDF's that I need in the main-script and also in the sub-scripts. Is it possible to use the UDF's and variables from the main-script also in the the sub-script? Bye |
||||||||
|
|
|||||||
If you call the UDF's from the main script and also call the child scripts from the main script everything will be ok because everything runs in the same kixtart process. There are several options for calling all functions without errors if you add a new function. -1 You can put all functions into one separate file and call that file that the top of your script. -2 You can put all function in separate files and call them one by one by walking through the folder that holds the function files. See below for an example. I have the example below at the top of almost all of my scripts. Code: ;Call each *.udf file until an error occurs or there are no more files to call. $udf = Dir(@SCRIPTDIR + "\functions\*.udf") While $udf <> "" And @ERROR = 0 Call @SCRIPTDIR + "\functions\" + $udf ;Get next *.udf filename. $udf = Dir() Loop |
||||||||
|
|
|||||||
As Mart has said if you define the functions in the main script then they are accessible in the sub-scripts, if you define the functions in the sub-script then they are available in the main script. Functions have a global scope. There are a couple of things to be watch out for:
|
||||||||
|
|
|||||||
Thanks for your responses! Now I had time to change my script, but it doesn't work. Until now I had 3 UDF's at the end of my main script. I put them all in a own file (udf.kix) and called this file in the first line of my main script (call "udf.kix"). But the UDF's are not accessible. One of the functions is "SpecialFolders". When I call this function later in the main script, I got this error: ERROR : unknown command [SpecialFolders]! I dot' know why... First I tried it with Include, but there appeared an error, that the file was not found (Include "udf.kix"). I tried it also with path (Include "..\udf.kix"). |
||||||||
|
|
|||||||
It would better to specify the path. Code: Call @scriptdir + "\functions.kix" The error you get is typical for a UDF that is not included or called. |
||||||||
|
|
|||||||
Thank you! Now it works! |
||||||||
|
|
|||||||
Thanks! Mart i am also facing the same problem and i searched for this help in internet but it is fulfilled here. |
||||||||
|
|
|||||||
Originally Posted By: Christof Thank you! Now it works! Great |
||||||||
|
|
|||||||
Nice Mart, looks like a better version of what I tossed up before, I'll sneak that one into my old setup :). |
||||||||
|
|
|||||||
Originally Posted By: Björn Nice Mart, looks like a better version of what I tossed up before, I'll sneak that one into my old setup :). Yeah well I did not made this up myself I found something similar here on the board and |
||||||||
|
|
|||||||
lol - that is the one I had. just my variable that diffed :P |