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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Values From Text Files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I would like to read values from text files, similar to how you would read values in an *.ini file in C. I would to be able to list it like I have below:

SUCHINSUCHVALUE = 1
SUCHINSUCHVALUE2 = WHATEVER

and have FP recognize this value. I have tried using _include and a header file, but this is to confusing having to #DEFINE etc. etc. Any help would be greatly appreciated. I want to be able to control program aspects without having to recompile or have access to VFP to edit a table.
 
Then use an INI file:

DECLARE integer GetPrivateProfileString IN Win32API AS GetINI string,string,string,string,integer,string

DECLARE integer WritePrivateProfileString IN Win32API AS SetINI string,string,string,string

lcVal=SPACE(1000)
lcINI="C:\mypath\mysets.ini"

lnLen=GetINI("MySect","MyEntry","",@lcVal,LEN(lcVal),lcIni)
IF lnLen>0
? 'Entry value is: ' + LEFT(lcVal,lnLen)
ELSE
? 'You gots a problem'
ENDIF

lcVal="Set Value to this"
IF SetINI("MySect","MyEntry",lcVal,lcINI) = 0
? 'You gots another problem"
ELSE
? 'Everything is groovy'
ENDIF Jon Hawkins
 
Why not use FiletoStr() and then alines() to convert the text file to an array? Then you can do want with it and then recreate the file as needed. --Dave
 
Storing values and retrieving...

If you can create all your INI variables naming to a uniform notation... say
iniMyScreenWidth = xxxxxxxxxxxxx
iniMyBackColor = RGB(192,192,192)
etc etc....
then, you can store all these variables ...
SAVE to myIni.ini ALL LIKE ini*

You can have your own dfault settings created in a command window or user selected settings accepted thru' a form saved in the above way.

When you want to get the value from this file, issue the command...
RESTORE from myINI.ini ADDITIVE

This is basically saving to a memo file. Note the memo file is not a text file and so external editing is not easy like a text file. Remember to add this file in your distribution.


ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
Hello,

Jon is right. Sometimes is better to use ini files, because they are text. And if you are located at the customer's computer, and you don't have VFoxPro installed there, is very hard to create those memo files. If this is the case, then you should consider to use the ini files, which can be modified in Notepad. :)

Hope this helps Grigore Dolghin
Class Software
Bucharest, Romania
 
Dave,

You could most definitely do it that way. The reason I didnt suggest that was because

1. The thread author indicated he was familiar with INI file structures.
2. As per your comments, you now have to write a parsing algorithm(using FILETOSTR and ALINES per your example) to extract the values. Why create the extra work? Jon Hawkins
 
Well, you may be correct, but regardless, you're going to have to do something with the stuff in the .ini file anyway. So whether you write things to the registry, an .ini file, a memo field in a table or flat-text ascii file, you're going to have to know how to program.

Dave Dardinger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top