Solved

INI files

Posted on 1998-08-12
3
231 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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

17 Experts available now in Live!

Get 1:1 Help Now