Solved

Using INI files

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…

912 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

22 Experts available now in Live!

Get 1:1 Help Now