This is the first of two utility functions (strGP to GetParameter is the second and will be posted tomorrow).

This module should be pasted into the INI module along with strPPS from yesterday.

strPP is the function I use in every application to store a value in an INI file. If the INI file does not exist, it will be created.

I prefer FUNCTIONs to SUBroutines because functions can return results. I figure it as a freebie. In this case, although I'm SENDING information from my application to the filestore, I can obtain useful stuff as a bonus. I elect to return the previous value, if any, from the INI file.

So now, if the user makes a change that is, in effect, not a change at all, I could detect this and issue a warning ("Did you know that you've not really changed anything?")

INI files can be quite powerful. Since an INI file stores driving information for an application, providing a means to switch INI files on-the-fly allows me to divert an application while it is running! My Document Cleanser contains the ability to detect user-commands to switch INI files, so i can have a table of rules describing how to clean a document, and then have that table of rules switch to another INI file, thereby collecting a totally different table of rules which can itself switch to another INI and so on.

To the user this means they can have a table that cleans English document, a table that cleans French, one for Spanish etc, and then hook them all up into a multi-lingual cleaning application.

And I don't have to change a single line of code or anything at the user site.

Yay! for INI files and Happy President's Day to those of you in the USA. I'll be there March 3rd, I promise ....

<pre>Public Function strPP(strSect As String, strKey As String, strValue As String, _
strFile As String) As String
' Procedure : strPP
' Description: This code sets a parameter in an INI file.
' Copyright: Chris Greaves Inc.
' Inputs: A file&section name, a key name, a value (may be null), a file name.
' Returns: STRING value of the parameter before it was replaced.
' Assumes: Nothing
' Side Effects: None.
' Tested: By the calls shown below.
Dim str As String
str = strFile
' Were we given only a local name?
If strBreakFileString(str, 0) = ":" Then
str = MacroContainer.Path & Application.PathSeparator & str
End If
' Is the INI extent absent?
If strBreakFileString(str, 3) = "" Then
str = str & ".INI"
End If
' return the previous value, if it exists.
strPP = strPPS(strSect, strKey, str)
Call apiPutPrivateProfileString(strSect, strKey, strValue, str)
'Sub TESTstrPP()
' Should create a SECTION3 in WOODY.INI file in template's directory.
'MsgBox strPP("section 3", "key3", "OLD value for key 3", "woody")
' Should use a SECTION3 in WOODY.INI file in template's directory.
'MsgBox strPP("section 3", "key3", "NEW value for key 3", "woody")
'End Sub
End Function