Solved

Using INI files

Posted on 1998-08-31
4
163 Views
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.
0
Comment
Question by:strongd
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
a111a111a111 earned 50 total points
ID: 1432192
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432193
0
 
LVL 2

Expert Comment

by:BergJC
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:
[System]
beep=none
ports=1
temp=yes
--------------------------

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")
0
 

Author Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now