John Weller wrote:
> I'm having a real brain stall here! I'm trying to write a simple routine to
> read and write to an ini file. I had a sample piece of code years ago but
> it is so long since I used it I've lost it. I have an app which only uses
> two pieces of data, a source path and a target path. I thought that it
> would be convenient if the user could edit them with notepad so decided to
> use an ini file. I've found the definitions fro GetPrivateProfileString and
> WritePrivateProfileString but I'm blowed if I can make them work! Does the
> ini file have to exist to write to it or will it create one; also the
> section? Anyone got some sample code out there that I could copy.
*-- DECLARE DLL statements for reading/writing to private INI files
DECLARE INTEGER GetPrivateProfileString IN Win32API AS GetPrivStr ;
String cSection, String cKey, String cDefault, String @cBuffer, ;
Integer nBufferSize, String cINIFile
DECLARE INTEGER WritePrivateProfileString IN Win32API AS WritePrivStr ;
String cSection, String cKey, String cValue, String cINIFile
* Example of saving form position to ini
* Write to ini
lcValue = ALLT(STR(MAX(THISFORM.TOP, 0))) + ',' + ;
ALLT(STR(MAX(THISFORM.LEFT, 0)))
*-- Write the entry to the INI file
=WritePrivStr("FormPositions", THISFORM.CAPTION, ;
lcValue, oApp.cProgramDirectory + INIFILE)
* Read from ini
lcBuffer = SPACE(10) + CHR(0)
lcOldError = ON('ERROR')
*-- Read the window position from the INI file
IF GetPrivStr("FormPositions", THISFORM.CAPTION, "", ;
@lcBuffer, LEN(lcBuffer), ;
oApp.cProgramDirectory + INIFILE) > 0
*-- If an error occurs while parsing the string,
*-- just ignore the string and use the form's
*-- defaults
ON ERROR llError = .T.
lnCommaPos = AT(",", lcBuffer)
lnTop = VAL(LEFT(lcBuffer, lnCommaPos - 1))
lnLeft = VAL(SUBSTR(lcBuffer, lnCommaPos + 1))
ON ERROR &lcOldError
IF !llError
THISFORM.TOP = lnTop
THISFORM.LEFT = lnLeft
ENDIF
ENDIF
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.