Answered by:

VFP9 Variables From File

Question

I'm trying to use the content of a txt file and use it as variables in a program.

client.txt
CLIENT="Client Name"
PROJECT="Project Name"

I would like the CLIENT, PROJECT to become a variables in my PRG holding what ever comes after the equal sign.

I found the following code: Currently it's reading and storing as a line. How do I change this?

LOCAL lnFileHandle && numeric file handle
lnFileHandle = FOPEN( "j:\70722\raw\ctlclient")
IF lnFileHandle = -1
&& error, could not open the file
&& do something to handle the error
RETURN
ENDIF
LOCAL lcLine && define a variable to hold each line
DO WHILE NOT FEOF( lnFileHandle) && loop through the file
lcLine = FGETS( lnFileHandle) && store each line in lcLine
?lcLine && do something with the line, such as display it
ENDDO

I agree with Tom Knauf that ALINES() is better here, but I assume you want to turn whatever's in the file into variables. You can use STREXTRACT() for that. Inside the loop through the array created by ALINES(), do something like this:

I agree with Tom Knauf that ALINES() is better here, but I assume you want to turn whatever's in the file into variables. You can use STREXTRACT() for that. Inside the loop through the array created by ALINES(), do something like this: