Search code examples
foxprovisual-foxpro

Getting Error When Using SET PROCEDURE TO


First let me say that I am very, very new to FoxPro and finding just the basics a bit of a learning curve.

I am attempting to create a program file (.prg) that has some public functions that I can call from my main code. I have added the program file "publicfunctions.prg" and included a simple function that returns a hard coded literal (just trying to make the mechanics work)

*!* This function is in the publicfunctions.prg file
FUNCTION GetFieldValue
    RETURN 'This is the value'
ENDFUNC

Then in my main program I attempt to use it but I am getting the error that the file does not exist. Here is the entirety of the code in the main program

*!* This is the main program logic    
SET PROCEDURE TO publicfunctions.prg

PRIVATE sFieldValue = ''

sFieldValue = GetFieldValue()

The error that I am getting is on the 'SET PROCEDURE TO publicfunctions.prg' statement. It is: "File 'publicfunctions.prg" does not exist."

I'm guessing that it can't find it because the default directory is not set to the path where the file exists. I tried adding the "SET DEFAULT TO" statement prior to the "SET PROCEDURE TO" statement but it didn't change the outcome at all.

I don't want to hard code the path so I guess my questions are these:

  1. Is my assumption correct about the default directory?
  2. If #1 is true then how can I set the default directory to the directory where the main program file is?
  3. Am I calling the function correctly? (If it can find it of course)

UPDATE
Per Hank's questions below I have added this additional information: The file "publicfunctions.prg" was added to the project using the "New" button on the Project Manager and the physical file is sitting right next to the "Main.prg" file in the file system folder.

enter image description here

enter image description here

I am using Microsoft Visual FoxPro 9.0

Any and all help will be truly appreciated.

Thanks,
Doug


Solution

  • VFP maintains a search path (which is separate from the Windows/DOS search path), which it will search for any PRGs, DBFs, etc that you reference in your code.

    You can check its current setting with the SET('PATH') function, and set it with SET PATH TO. These places are searched in addition to whatever the current default directory (which you can verify with the SET('DEFAULT') and CURDIR() functions.

    This will show what these currently are:

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

    These are documented well in VFP's help - check there for a much better explanation.