I have declared a couple of global variables in my main program and can access these values from another module which I load with the load command. However I cannot set these variables from the loaded module. How do I do that? I have the following code:
Module mod1
PERS bool red := FALSE;
PERS bool black := FALSE;
PERS bool green := FALSE;
PROC main()
LOAD “C:/folder/file.prg”;
%“paintprg:callMe”%;
UNLOAD “C:/folder/file.prg”;
ENDPROC
ENDMODULE
MODULE mod2
PROC callMe()
red := TRUE; ! This doesn’t work
ENDPROC
ENDMODULE
Why won’t that work and how should I do to solve it?
Hi
I recommend you to use .MOD files for your modules.
In your example, file.prg should be Mod2.mod
I usually use a module containing only the PERS variables, such as:
MODULE Globals
PERS bool red := FALSE;
PERS bool black := FALSE;
PERS bool green := FALSE;
ENDMODULE
Then a small module that loads the most of the code, such as:
MODULE StdTask
PROC Main()
LOAD “C:/folder/modmain.mod”;
red:=FALSE;
TPWrite “Now red is FALSE”;
%“MainEntry”%;
IF red THEN
TPWrite “Now red is TRUE”;
ENDIF
ENDPROC
ENDMODULE
And the main module
MODULE ModMain
PROC MainEntry()
red := TRUE; & nbsp; ! This will work
Save “GLOBALS.MOD”; ! Not recommended, but legal
ENDPROC
ENDMODULE
Saving Globals.mod will save new PERS values in the file, that can help if you P-Start the controller very often. But do not write to often on the flash-disk or you can damage it (so I’ve been told, even if it has never happend to me).
Can I load a module without an absolute path? Does it understand relative paths or environment variables?
Actually full path gives me
System1/RAPID/T_ROB1/Module1(280,14): String too long(141): The string LOAD is too long. 12/07/2019 2:51:29 PM General
I believe that the real problem lies in the parentheses.
Would you recommend adding parentheses?
I am using windows syntax with backslashes (path has spaces as well) … Not sure it matters?
RemoveDirWithContent("HOME:/Test");
Where does HOME point to or how do i set HOME ?
This is interpreted as the path to the home directory of the current system.
Ah, folder below your system (in controller tab) …
Loading more than once is bad, can I check loaded?