No announcement yet.

Passing arguments, strings or variables from .4XE file to file

  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing arguments, strings or variables from .4XE file to file

    I have set up multiple programs to run sections of a larger program. So I use:

    --In program START.4XE---

    if(!file_Exists("HELP.4XE"))putstr("HELP.4XE not found\n"); file_Run("HELP.4XE",0);

    This launches the HELP.4XE program.

    If I wanted to pass information across, either a variable(s), string(s) or an argument, what is the correct syntax?

  • #2
    var myArray[10];
    var myString:="Hello world";
    var secondArray[100]:=[55,66,77];

    myArray[0]:=3; //this is the number of items to pass into your program

    //These are the values that you pass in.
    myArray[1]:=37; //passing in a number
    myArray[2]:=myString; //passing in a string
    myArray[3]:=secondArray; //passing in the array


    If you use file_Run I believe any array/string you pass in must be a global variable. If you use file_Exec it doesn't matter.

    The main function in "HELP.4XE" should then look like this. (Note: it will turn into "HELP.4FN" when you add the variables in the main function)

    func main(var valueone, var valuetwo,var valuethree)



    print(valuethree[0]," ",valuethree[1]," ",valuethree[2],"\n");

    repeat forever

    Make sure the number than you put in myArray[0] matches the number of variables than your main function takes in. The compiler cannot check this for you and stuff will crash if it's different.


    • #3

      I didn't realize that the extension changes when variables are added.

      .4FN instead of .4XE

      I missed that in the documentation. Thank you very much.


      • #4

        Thanks ipaq3115 for the information. Did you get them from the manual or from the forums? I could not find it in the documentation?

        I am currently building a program using file_run to call "subprograms"

        Looking in the "PICASO-4DGL-Internal-Functions-REV6.2.pdf" it says :
        Any memory allocations in the main FLASH program are released, however, the stack and globals are maintained. func 'main' in the called program accepts the arguments, if any. If arglistptr is 0, no arguments are passed, else arglistptr points to an array, the first element containing the number of additional elements in the array which contain the arguments.The disk does not need to be mounted, file_Run automatically mounts the drive. So I think, it means that also local variables of functions are retained since as far as as remember they go in the stack.


        • #5

          I got it from the manual and the forums... a lot I figured out from the sample programs though. There's good stuff in there you just have to dig around to find it. They have an example in there showing one program calling another and passing variables and all that stuff, just showing how it works.

          I seem to remember file_Run killing my local variables back when I was working all that out. Right now I'm just careful about my memory allocations and I make sure to keep the space free and I just use the file_LoadFunction() call which acts similarly to file_Execute(). It leaves all your memory allocations and variables alone.


          • #6

            Ok, thanks for the advices.


            • #7

              It is rather difficult to create documentation that does not overload the reader with unnecessary info.

              The RUNDEMOS.4DG program and all the other associated programs was created as a comprehensive
              insight into 'howto dostuff' and is really the definitive guide.

              For passing values too/from child processes, I suggest a good look at the way SLIDERS.4DG works.

              Also, a valuable source is the tetris program that loads popup windows and returns values etc.


              • #8
                Not sure how SLIDERS.4DGcan help with "passing values too/from child processes". Can see any child process.Actually RUNDEMO.4DG seems to only call the sub-program without arguments.
                HTML Code:
                       file_Run("sliders.4xe",0);                    // just run the prog, no args
                       goto redo;


                • #9


                  I have similar problem.

                  I created a program with a main and several other functions.
                  I can call this program from another program with file_Exec just fine.
                  Now I would like to pass a parameter to this program.

                  I added a parameter to the main function and the compiler created
                  me a 4FN file from this program. Its ok.
                  But, when I tried to call the function with

                  dialogPtr := file_LoadFunction(name);
                  rc := dialogPtr(inputOutput);

                  nothing happened.
                  I got a pointer, but my sub-program didn't work.
                  The problem is there are more than one function in the 4FN file,
                  and I probably called not the main one.
                  (If I put only one function into the 4FN file, then it worked fine.)

                  Is it possible to create 4FN file with more function?

                  Thank in advance,


                  • #10

                    You should be calling the "main" function. Any other functions
                    would have to be called from that function. For example in
                    your 4fn file try this.

                    func one()

                    func two()

                    func main(var functiontocall)

                    if(functiontocall==1) one();
                    if(functiontocall==2) two();



                    • #11

                      Sorry for bothering you, it is working now.
                      So the entry function should be "main" in this case.
                      (I tried it also, but somehow it wasn't work for me at first.)



                      • #12
                        Hi Eric,

                        file_Run("sliders.4xe",0); // just run the prog, no args
                        goto redo;

                        That is an earlier RUNDEMOS, please have a look at the version shipped with the latest release.
                        It gives another alternative that allows the child process globals to be accessed by the parent

                        case 2:

                        fncHandle := file_LoadFunction("sliders2.4xe"); // load the function

                        slidervals := fncHandle&0x7FFF; // note that memory allocations for transient programs are biased with 8000h
                        slidervals++; // and that all globals start at '1'

                        slidervals[0] := 25; // set sliders to initial positions
                        slidervals[1] := 20;
                        slidervals[2] := 30;
                        slidervals[3] := 15;
                        slidervals[4] := 35;
                        slidervals[5] := 20;
                        slidervals[6] := 40;
                        slidervals[7] := 25;
                        slidervals[8] := 45;
                        slidervals[9] := 5;

                        r := fncHandle(); // call the function

                        gfx_MoveTo(10, 10);
                        print("Return value = 0x", [HEX] r,"\n");
                        print("Slider 1 ", slidervals[0]," Slider 2 ", slidervals[1],"\n");
                        print("Slider 3 ", slidervals[2]," Slider 4 ", slidervals[3],"\n");
                        print("Slider 5 ", slidervals[4]," Slider 6 ", slidervals[5],"\n");
                        print("Slider 7 ", slidervals[6]," Slider 8 ", slidervals[7],"\n");
                        print("Slider 9 ", slidervals[8]," Slider 10 ", slidervals[9],"\n");
                        putstr("\n\nTouch to continue....");
                        while(touch_Get(TOUCH_STATUS) != TOUCH_RELEASED);

                        of course, the method ipaq3115 is also a valid alternative.



                        • #13

                          OK, I had the earlier version. I will check if that works with my test program.

                          Thanks Dave