Solved

INI files

Posted on 1998-08-12
3
229 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
Comment Utility
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
Comment Utility
Post your email address, and I will send you an excelent word doc on using ini files.
0
 

Author Comment

by:PriyaMani
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

772 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

15 Experts available now in Live!

Get 1:1 Help Now