0

i've been trying to do this for a while but i can't figure out how. I want to call a procedure from an external .prg file to another .prg.

So, for that, i do:

SET PROCEDURE TO cenas2.prg Additive \\ cenas2.prg is the filename with the procedure called myproc inside
Do myproc

My problem is , when i run it i get the error : File 'cenas2.prg' does not exist.

So, i ran the following code:

WAIT WINDOW 'Path: ' + SET('PATH') + CHR(13)+CHR(10) + 'Default drive: ' + SET('Default') + CHR(13)+CHR(10) + 'Current directory: ' + CURDIR()

And i got :

Path :

Default Drive C:

Current Directory: \PHC20CRP\

cenas2.prg is located inside PHC20CRP , and when i run file("cenas2.prg") it returns me true , so i don't think it makes any sense to return me file does not exist when i try to set procedure. Can anyone help me??

Thanks

J.Snow
  • 27
  • 11

3 Answers3

0

Simply use the fullpath:

set procedure to ("c:\PHC20CRP\cenas2.prg") additive

Instead of setting procedure to and then using a procedure, it might be safer to execute code without setting procedure to. ie:

do myProc In ("c:\PHC20CRP\cenas2.prg")

I prefer this style, because I can execute procedures which are named same in different procedure files easily. With "set procedure" approach, which one would execute depends on the order of instantiation and not predictable.

Cetin Basoz
  • 22,495
  • 3
  • 31
  • 39
  • I keep getting the same error... this is so weird. Any idea what else it could be? – J.Snow Nov 28 '16 at 15:32
  • No, Folder\File are visible and set to full permitions. Coudn't discover why it says file does not exist.. :( – J.Snow Nov 29 '16 at 18:08
0

Already discoveres the problem. I had to force a parameter inside the procedure so otherwise it wouldn't execute. Thanks for all your help!

J.Snow
  • 27
  • 11
0

Let me ask you this. Is your cenas2.prg a SINGLE ROUTINE?? and not a program file that has MANY procedures and functions.. If so, the SET PROCEDURE TO is not needed, you should be able to call it directly, just having it as part of the project.

Typically a "SET PROCEDURE" file is a bunch of routines in a single .prg file so you don't have dozens or even hundreds of common routines bloating your development folder, such as

*/ This is MyProcedureFile.prg
function oneFunc()
...
endfunc

procedure someOtherProc()
...
endproc

function specialTest()
...
endfunc

*/ End of this complete .prg

then you would have

set procedure to MyProcedureFile additive

and all the functions are visible to the application. If your .prg file is the only routine on its own, you don't need SET PROCEDURE TO.

DRapp
  • 47,638
  • 12
  • 72
  • 142
  • oh thanks! it was a single routine so i did just do cenas2.prg and it worked, thanks it will save me lots of time! – J.Snow Dec 19 '16 at 16:38
  • @J.Snow, glad it is resolved. Take a look at help -> tour for site etiquette and marking answers as solved so others know what worked too. – DRapp Dec 19 '16 at 20:48