Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

INI File Information Saving & Retrieving

Posted on 1999-06-25
2
Medium Priority
?
213 Views
Last Modified: 2010-05-02
I have Drive & Directory Controls in a project
How can I save the drive and directory info in
a INI ( Text ) file and retrieve the same info
back when the program is executed again.
0
Comment
Question by:deepakahuja
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
Thamaz earned 40 total points
ID: 1519867
You can use WritePrivateProfileString API to write the information in a windows .INI file format. Example:

Public 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

Public 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


Sub AddToINI(ByVal DriveInfo as String, _
             ByVal DirInfo as String)
   Dim rc As Long

   rc = WritePrivateProfileString("DriveDirSection", _
   "Drive", DriveInfo, _
   "MYAPP.INI")

   rc = WritePrivateProfileString("DriveDirSection", _
   "Dir", DirInfo, _
   "MYAPP.INI")

   MsgBox "Drive & Dir is now entered in MYAPP.INI file."

End Sub



& the use GetPrivateProfileString API to retrieve the information. Example


Sub GetFromINI(ByRef DriveInfo as String, _
               ByRef DirInfo as String)
   Dim rc As Long
   Dim RetStr as String

   RetStr = String(5, Chr(" "))

   rc = GetPrivateProfileString("DriveDirSection", _
   "Drive", "C:", RetStr, Len(RetStr)-1, _
   "MYAPP.INI")

   DriveInfo = Left(RetStr, Instr(RetStr, Chr(0))-1))

   RetStr = String(130, Chr(" "))

   rc = GetPrivateProfileString("DriveDirSection", _
   "Dir", "\", RetStr, Len(RetStr)-1, _
   "MYAPP.INI")

   DirInfo = Left(RetStr, Instr(RetStr, Chr(0))-1))

   MsgBox "Drive & Dir is now in Vars from MYAPP.INI file."

End Sub


I hope that this help you. Gd Lk.
0
 
LVL 1

Expert Comment

by:Thamaz
ID: 1519868
You can get the description of the params & the use of the API in the documentation of the Win32API
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

721 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