Re: Trying to use *.ini file as a database record



On Thu, 7 Jul 2005 10:17:30 -0400, "RAD Software" <rad@xxxxxxxxxxxxxxx> wrote:

>I'm experimenting with using the
>
>GetPrivateProfileString and WritePrivateProfileString APIs
>
>as a way of creating and manipulating a database file.
>
>One of the first things I need to be able to do at program startup is get a
>list of the section names in the *.ini file.
>
>MS-Online says that if I call GetPrivateProfileString and use a NULL for the
>lpSectionName parameter, the function will return a Null-character delimited
>list of all the section names.
>
>So, using a 2.3mb *.ini file containing 8,181 section names, with about 10
>keynames in each section, I tried
>
>success = GetPrivateProfileString(NULL, vbnullstring, vbnullstring, sResult,
>nSize, DataFileName)
>
>but the compiler says this is an improper use of NULL.
>
>In doing a little research, I found GetPrivateProfileSectionNames, so I
>declared it and tried
>
>success = GetPrivateProfileSectionNames(sResult, nSize, DataFileName)
>
>but it returns false for success and zero for nSize.
>
>The total character space of the all the section names would be about 10,000
>characters, so I tried buffering sResult with both space(25000) and
>string(25000, Chr(0)), to no avail.
>
>Can anyone tell me what I'm doing wrong here, or have any advice as to how
>to get a list of section names in a *.ini file?

Public Sub DeleteEntry(sSectionName As String, sItemName As String)
' Purpose: To remove an entry from an INI file
' Example/Note: xxx
' !! Assumes/Pre: Nothing
' Parameters:
' sSectionName as String -
' sItemName as String -
' Returns: Nothing
' Success-
' Failure- Raises error on failure
' Revision history:
' 2005-Mar-23 12:02 [Michael Johnson] Initial creation
Dim lDummy As Long

Call TraceEnters(MODULE_NAME & "::DeleteEntry")
TraceDetail = "To remove an entry from an INI file"

'' Can't get WritePrivateProfileString to accept a Null, tried:
' Private Declare Function DeletePrivateProfileEntry Lib "kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByRef lpKeyName
As Any, lpString As Any, ByVal lpFileName As String) As Long
' lDummy = DeletePrivateProfileEntry(sSectionName, 0, 0, szFileName)
' lDummy = DeletePrivateProfileEntry(sSectionName, Null, Null, szFileName)
lDummy = WritePrivateProfileString(sSectionName, sItemName, vbNullString,
szFileName) ' << This works
ExitThis:
Call TraceExits
Exit Sub
End Sub

Having said that, you may want to do a little research into SQLite before you
settle in an INI file.

See
* http://republika.pl/roed/litex/index.html
* http://www.ch-werner.de/sqliteodbc/

The ODBC driver comes with command line tools to create an ODBC DSN connection.
(The instructions for the command line parameters is documented within the
source code, in the procedure comments.)

Hope this helps!
_______________________
Michael B. Johnson
.



Relevant Pages

  • Re: Writing INI section failing
    ... It returns true but when looking inside the INI file there's no new added ... Public Function WriteINIFileSection(ByVal sEntryType As String, ... WriteINIFileSection = False ... Well the problem is your call to WritePrivateProfileString. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: what are these functions?
    ... > Declare Function GetPrivateProfileString Lib "kernel32" Alias ... > lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As ... > Declare Function WritePrivateProfileString Lib "kernel32" Alias ...
    (microsoft.public.vb.general.discussion)
  • Re: Reading an INI file
    ... > Does anyone have any code for reading an INI file for my application? ... Public Declare Function GetPrivateProfileString Lib "Kernel32" Alias ... "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ... Public Declare Function WritePrivateProfileString Lib "Kernel32" Alias ...
    (microsoft.public.vb.general.discussion)
  • Re: Relink question
    ... At least I can begin to understand how the values get to the GetPrivateProfileSection and WritePrivateProfileString functions. ... neither your frontend nor your INI file should be in any of these "known shared" folders. ... ByVal lpReturnedString As String, _ ...
    (microsoft.public.access.formscoding)
  • What is the problem with GetPrivateProfileString?
    ... GetPrivateProfileString called from VB5 SP3 works GREAT on my XP machine, but on my '98 machine it just returns a blank buffer and a zero length indication regardless of what is in the INI file. ... I made the call to WritePrivateProfileString with all arguments except for the filename NULL to map the INI file to the registry, but it doesn't seem to be hiding in there as a result. ... Like most Microsoft problems I run into, this one has also had lots of postings along with replies the don't work, but apparently no one has ...
    (microsoft.public.vb.enterprise)