hexagon logo

Make forms and external files portable

I've been using forms lately, and I find it annoying to change file paths any time I need to move the program to another directory or machine. Now I use a little extra code to make it work from any directory without editing anything. I place all external files in the same folder as the PC-DMIS program, and when I need to I can drag/drop or copy/paste the entire folder to a new directory. Works out of the box!

Use the GetProgramInfo function to read the current directory location of your part program when it executes:

            ASSIGN/PATH=GETPROGRAMINFO("PARTPATH")

CS1        =FORM/FILENAME= PATH+"[I]FORMNAME[/I].FORM"
            PARAM/TEXT1.TEXT=PATH   [COLOR=#008000]<--- [I]this line optional, see below[/I][/COLOR]
            PARAM/=
            ENDFORM/


If your form references other external files you will need to pass the file path into the form. There are a few ways to do this.

The first is using the optional line from above. Then whenever you need to call the variable you can reference TEXT1.TEXT. Set the Visible property to No.
The second (thanks to bjacobson for this one) is to use the expression =variable("PATH") from inside the form.
A third option is to declare a local variable in the form from inside the advanced properties of TheFrame/TheView, and use the same expression from the second option.



With any of these you should be able to concatenate the file name onto the end of the file path.

strImgPath=TEXT1.Text & "MASTER.jpg"
Bitmap1.Bitmap=strImgPath