Solved

Using INI files

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library 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…
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…

830 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