Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create .ini file to pull and put settings to.

Posted on 1999-01-25
3
Medium Priority
?
265 Views
Last Modified: 2010-05-03
How can I create a .ini file to save program settings to and retrieve the next time the program is loaded?
0
Comment
Question by:q_ship
[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
3 Comments
 
LVL 4

Accepted Solution

by:
CraigLazar earned 200 total points
ID: 1470704
Hi
here is some code thath does the trick
Private Sub Command1_Click()
       CommonDialog1.Action = 1
       PathField.Text = CommonDialog1.filename
       Dim path As String
       Dim PathName As String
       PathName = PathField.Text
       Open "c:\tflorist.InI" For Output Shared As #1
       Write #1, PathName    ' Write comma-delimited data.
       Write #1,   ' Write blank line.
       Close #1
       Unload Registry
End Sub

this function pops up a form for the user to browse and select the database file. It then auto creates an ini file called tflorist.ini with the path that the user selected

'********  to read from the ini **********
 Public Function databasePath()
On Error GoTo error_handler:
        Open "c:\Tflorist.InI" For Input Shared As #1
        Input #1, TempPath
        Close #1

error_handler:
If Err.Number = 53 Then
       MsgBox "Please can you use the next screen to Locate the Database file on the Network Server", vbInformation
       Load Registry
       Registry.Show 1
      Resume
       End If
End Function

This function opens and reads the ini file for it's value

Now if you sre going to have multiple values in an ini file you need to make calls to the Api
getprivateprofile String
writeprivateprofile string

'Declare statements for the Dll's which go in the General Declarations Section of the form
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Private Declare Function WritePrivateProfileStringA Lib "kernel32.dll" (ByVal ipszsection As String, ByVal ipszkey As String, ByVal ipszString As String, ByVal ipszfile As String) As Long

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _

Dim wTest As Long
Dim wAppName As String
Dim wKeyName As String
Dim wString As String
Dim wFile As String
Dim rAppName As String
Dim rKeyName As String
Dim rDefault As String
Dim rReturnedStrings As String
Dim rSize As Long
Dim rFile As String
Dim rTest As Long
Dim Tempbuff As Variant

Call DatPath
Dim teste As String
dbpath = dbpat
rAppName = "Drivers"
rKeyName = "bpsdriver"
rDefault = "not"
rReturnedStrings = Tempbuff
rSize = 20
rFile = "c:\windows\system.ini"
Tempbuff = GetPrivateProfileString(rAppName, rKeyName, rDefault, rReturnedStrings, rSize, rFile)
If Tempbuff <> 10 Then
    wAppName = "Drivers"
    wKeyName = "Bpsdriver"
    wString = "bpsdrv.dll"
    wFile = "system.ini"
    wTest = WritePrivateProfileStringA(wAppName, wKeyName, wString, wFile)
End If


good luck
Craig
0
 
LVL 18

Expert Comment

by:mdougan
ID: 1470705
Just a note, GetPrivateProfileString has a place where you can specify "default" values - so, in the procedure where you call it, if GetPrivateProfileString does not find your INI file, then it will return the defaults you provide - so you can populate your program variables.  

Then, in your application, when you close down, you should WritePrivateProfileString your program variables to the INI file.  If the INI file does not exist (as it wont the first time you run), then it will create it for you with the proper Section names etc.

The next time you run your program, then GetPrivateProfileString should be able to find your INI file.

0
 

Author Comment

by:q_ship
ID: 1470706
Thank you for the code, that points me in the right direction!
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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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

636 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