Solved

INI files

Posted on 1998-08-12
3
232 Views
Last Modified: 2010-04-30
Hi,
Could someone enlighten me on INI files ? How does one create and use them.
Thanks,

PM
0
Comment
Question by:PriyaMani
3 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 50 total points
ID: 1468657
To create and use INI files you will have to add to API declares to your project:
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
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
An INI files contents are in this layout:
  <ApplicationName>
  KeyName=Value
To write to an INI file use this call:
  lRes = WritePrivateProfileString("MyAppName", "MyKeyName", "MyValue", "MyApp.ini")
This will create (if it doesn't already exist) a file called MyApp.ini in the windows directory.  The contents will be:
  <MyAppName>
  MyKeyName=MyValue
To retrieve the value, use this code:
  Dim sBuffer As String * 255
  lRes = GetPrivateProfileString("MyAppName", "MyKeyName", sBuffer, Len(sBuffer), "DefaultValue", "MyApp.ini")
  Debug.Print Left$(sBuffer, lRes)
This will print the value above.  If the value doesn't exists, it will print:
  DefaultValue.
0
 
LVL 3

Expert Comment

by:jjmartin
ID: 1468658
Post your email address, and I will send you an excelent word doc on using ini files.
0
 

Author Comment

by:PriyaMani
ID: 1468659
Will take some time to understand & try out the proposed answer. In the meantime,

For jjmartin:
My email address : marie4@ameritech.net
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

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…
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…
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…

809 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