Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to extract a value from a CONFIG.FPW line 3

Status
Not open for further replies.

TheSofty

Programmer
Jul 8, 2003
35
IT
Hi all,

in a CONFIG.FPW file I have:

SCREEN = OFF
SYSMENU = OFF
STATUS BAR = OFF
KEYCOMP = WINDOWS
SORTWORK = C:\WINDOWS\TEMP
PROGWORK = C:\WINDOWS\TEMP
EDITWORK = C:\WINDOWS\TEMP
PATH = \\Server2000\DATA
STATUS = OFF
TITLE =
RESOURCE = OFF

I'd like to extract the PATH value, i.e. the string "\\Server2000\DATA"

What's the best way?

Thanks
 
Thesofty

I would suggest you use an "ini" file rather than a config file to store your path. That makes it easier to extract values.

You then can use the GetStringProfile API call to retreive the value:
DECLARE INTEGER GetProfileString IN kernel32;
STRING lpAppName,;
STRING lpKeyName,;
STRING lpDefault,;
STRING @ lpReturnedString,;
INTEGER nSize

Have a look at faq184-2916.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Using VFP you want to determine what is in the config.fpw after PATH= ?
As far as I know path= is not a valid config.fpw entry.
Config.fpw settings are available with the sys() functions.
If you want to open config.fpw and read the value use lowlevel functions like fopen() and fread() or fgets().
In the helpfile there are enough examples to get you up and running.

Rob.
 
Mike,

thanks for your replay. But in this case I cannot use an .INI file. I must read that value right there. Yeah, I could create a SCRATCH.INI file just for that, but I consider it a suboptimal option, so I'd avoid if I could.

Any other hint?

 
rob444,

thanks for your replay. I can assure you that PATH in CONFIG.FPW always worked fine for its intended goal.

I looked at all SYS() functions before posting, but I couldn't come up with something useful. Have you a number for me to investigate? Maybe I missed it.

I knew about LLFs. I just hoped there was a different/better way. ;o)

 
Thesofty,

If you simply want to know the path settings, you can get it by doing SET("PATH").

However, if you must read the Config file, you could try something like this:

* Copy file to a string
lcStr = FILETOSTR("config.fpw")

* Make an array containing lines from file
lnLines=ALINES(laArray,lcStr)

* Search the array for the Path line
FOR lnI = 1 to lnLines
IF "PATH" $ UPPER(laArray(lnI))
* Extract the path
lcPath = SUBSTR(laArray(lnI),AT("=",laArray(lnI))+1)
EXIT
ENDIF
ENDFOR

I haven't tested this code, but I think it should work.

Mike


Mike Lewis
Edinburgh, Scotland
 
Hi

cConfig = "myPath\CONFIG.FPW"
or
cConfig = SYS(2019)... if used by FoxPro

now path line..string can be extracted as...

cPath = ATLINE("PATH",UPPER(FILETOSTR("CONFIG.FPW")))
or
cPath = ATLINE("PATH",UPPER(FILETOSTR(cConfig)))

Then you can substring and take the path alone..

or.. if your application is setting the path.. the,,

myPath = SET("PATH")

:)

ramani :)
(Subramanian.G)
 
Thesofty,

Another variant using a cursor

CREATE CURSOR temp (cline C(254))
APPEND FROM config.fpw SDF
REPLACE TEMP.cline WITH UPPER(TEMP.cline) ALL
LOCATE FOR [PATH] $ TEMP.cline
lcPath = CHRTRAN(TEMP.cline,[ ],[])
lcPath = CHRTRAN(TEMP.cline,[PATH=],[])
? lcPath




FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Post in haste, repent at leisure

CREATE CURSOR temp (cline C(254))
APPEND FROM config.fpw SDF
LOCATE FOR [PATH] $ UPPE(TEMP.cline)
IF FOUND()
[tab]? SUBSTR(TEMP.cline,AT([=],TEMP.cline) + 1)
ELSE
[tab]MESSAGEBOX([No path found])
ENDI

In the previous version, had the path contained a space, the path returned would have been incorrect. [blush]

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Thank you guys for your help. Now I have some alternatives to consider. A star to you.

 
Ramani,

Are you sure about ATLINE()? I thought it returned the line number, not the actual line. But there is a function that returns the actual line ... MLINE(), if memory serves. I might be wrong about this.

Mike


Mike Lewis
Edinburgh, Scotland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top