Using INI files

Posted on 1998-08-31
Last Modified: 2010-04-30
Can someone give me some sample code so I can learn how to use ini files in my programs.  Or how to go about doing this.  Thanks.
Question by:strongd
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

a111a111a111 earned 50 total points
ID: 1432192

Expert Comment

ID: 1432193

Expert Comment

ID: 1432194
Here's the code I use:

Declare these:

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Example INI file:

To get variables from the INI file:

ret% = GetPrivateProfileString("System", "beep", "", tempvariable, 4, "c:\windows\example.ini")

This reads "none" into tempvariable. Everything is pretty self-explanatory, except the "" in the third parameter. That is the default value you want if there is a problem retrieving it from the INI file.

Now, to write back to the INI file:

ret% = WritePrivateProfileString("System", "beep", "none", "C:\windows\example.ini")

Author Comment

ID: 1432195
Thanks.  I use what is on your web page.  Later

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question