Solved

Using INI files

Posted on 1998-08-31
4
168 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 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

10 Experts available now in Live!

Get 1:1 Help Now