How to Read/Write to INI FIle 
Author Message
 How to Read/Write to INI FIle

Below is an .INI file for R&R Report Writer.
Could someone please post the code to retrieve
parts of this file and also to write new data to it.
..............................................................................
[Export]
Export1=Excel PivotTable, RRXTAB.DLL
Export2=Excel Chart, RRXCHART.DLL
[Defaults]
ProgDir32=D:\Program Files\R&R Report Writer\
TemplateDir=D:\Program Files\R&R Report Writer\Template
[Data Dictionary]
DataDict=D:\Program Files\R&R Report Writer\Sample\rrdict.dbf
DataDictIndex=D:\Program Files\R&R Report Writer\Sample\rrdict.ndx
[User Info]
UserName=Wakanla TwoBears
Company=Parkway Hospital
[Frame]
Show=1
Left=44
Top=44
Right=644
Bottom=455
[Save List]
BandWidth=80
ActionBar=1
FormatBar=1
FieldNames=0
PasteArgs=1
ShHzRul=1
ShVtRul=1
ShGrd=1
ShowCalcComment=1
IVer=2
CloseInsDlg=0
..............................................................................

I received this example from a NG but don't really know
how to use it.  

.............................................................................
Declare the following API calls:

Declare Function GetPrivateProfileStringA Lib "kernel32.dll" (ByVal
inisection As String, ByVal inientry As String, ByVal returndefault As
String, ByVal inientrystring As String, ByVal inientrysize As Integer,
ByVal inifilename As String) As Integer

Declare Function WritePrivateProfileStringA Lib "kernel32.dll" (ByVal
inisection As String, ByVal inentry As String, ByVal inientrystring As
String, ByVal lpFileName As String) As Integer

For simplicity sake, define the following two functions:

Function getinidata(section As String, keyword As String) As String
'--------------------------------------------------
' Calls the windows API to get values from trs.ini file
' Returns data
'--------------------------------------------------

Dim length, returned$

getinidata = ""
If section <> "" And keyword <> "" Then
    returned$ = Space$(256)
    length = GetPrivateProfileStringA(section, keyword, "0", returned$,
256, windir$ & "trs.ini")
    returned$ = Left$(returned$, length)
    getinidata = returned$
End If

End Function

Function setinidata(ByVal section As String, ByVal keyword As String,
ByVal inidata As Variant) As Variant

'--------------------------------------------------
' Calls the windows API to set values in trs.ini file
' returns origional value
'--------------------------------------------------

Dim retvalue, inistring$
setinidata = ""

If section <> "" And keyword <> "" Then
    inistring$ = LTrim$(inidata)
    retvalue = WritePrivateProfileStringA(section, keyword, inistring$,
windir$ & "trs.ini")
    If retvalue <> 0 Then setinidata = inidata
End If

End Function

In your code, refer to these two by simply using the section and
parameter:
E.g.:
nrMRUs% = getinidata("MRUFiles", "Number")
If setinidata("MRUFiles", "order", neworder$) <> neworder$ Then Msgbox
"Error writing .ini file"

In this way, you can later update your getinidata() and setinidata()
functions to use the registry, for instance (Which you should do if you
want to be MS compliant....), without changing your code.
..............................................................................

How does one read the username from the [UserInfo]
into variables, or the TOP,LEFT,BOTTOM coordinates
from [Frame]?

How does one change these entries?

How does one add new entries to this INI file?

                        Thanks,
                                Magic



Sun, 24 Jun 2001 03:00:00 GMT  
 How to Read/Write to INI FIle
I think I might make this my sig

Don't you ever read the posts in here. This question has been hashed over at
least a dozen times over the last two weeks alone. Reset your news reader
and start reading, instead of posting just to see your name.

Quote:

>Below is an .INI file for R&R Report Writer.
>Could someone please post the code to retrieve
>parts of this file and also to write new data to it.
>...........................................................................
...
>[Export]
>Export1=Excel PivotTable, RRXTAB.DLL
>Export2=Excel Chart, RRXCHART.DLL
>[Defaults]
>ProgDir32=D:\Program Files\R&R Report Writer\
>TemplateDir=D:\Program Files\R&R Report Writer\Template
>[Data Dictionary]
>DataDict=D:\Program Files\R&R Report Writer\Sample\rrdict.dbf
>DataDictIndex=D:\Program Files\R&R Report Writer\Sample\rrdict.ndx
>[User Info]
>UserName=Wakanla TwoBears
>Company=Parkway Hospital
>[Frame]
>Show=1
>Left=44
>Top=44
>Right=644
>Bottom=455
>[Save List]
>BandWidth=80
>ActionBar=1
>FormatBar=1
>FieldNames=0
>PasteArgs=1
>ShHzRul=1
>ShVtRul=1
>ShGrd=1
>ShowCalcComment=1
>IVer=2
>CloseInsDlg=0
>...........................................................................
...

>I received this example from a NG but don't really know
>how to use it.

>...........................................................................
..
>Declare the following API calls:

>Declare Function GetPrivateProfileStringA Lib "kernel32.dll" (ByVal
>inisection As String, ByVal inientry As String, ByVal returndefault As
>String, ByVal inientrystring As String, ByVal inientrysize As Integer,
>ByVal inifilename As String) As Integer

>Declare Function WritePrivateProfileStringA Lib "kernel32.dll" (ByVal
>inisection As String, ByVal inentry As String, ByVal inientrystring As
>String, ByVal lpFileName As String) As Integer

>For simplicity sake, define the following two functions:

>Function getinidata(section As String, keyword As String) As String
>'--------------------------------------------------
>' Calls the windows API to get values from trs.ini file
>' Returns data
>'--------------------------------------------------

>Dim length, returned$

>getinidata = ""
>If section <> "" And keyword <> "" Then
>    returned$ = Space$(256)
>    length = GetPrivateProfileStringA(section, keyword, "0", returned$,
>256, windir$ & "trs.ini")
>    returned$ = Left$(returned$, length)
>    getinidata = returned$
>End If

>End Function

>Function setinidata(ByVal section As String, ByVal keyword As String,
>ByVal inidata As Variant) As Variant

>'--------------------------------------------------
>' Calls the windows API to set values in trs.ini file
>' returns origional value
>'--------------------------------------------------

>Dim retvalue, inistring$
>setinidata = ""

>If section <> "" And keyword <> "" Then
>    inistring$ = LTrim$(inidata)
>    retvalue = WritePrivateProfileStringA(section, keyword, inistring$,
>windir$ & "trs.ini")
>    If retvalue <> 0 Then setinidata = inidata
>End If

>End Function

>In your code, refer to these two by simply using the section and
>parameter:
>E.g.:
>nrMRUs% = getinidata("MRUFiles", "Number")
>If setinidata("MRUFiles", "order", neworder$) <> neworder$ Then Msgbox
>"Error writing .ini file"

>In this way, you can later update your getinidata() and setinidata()
>functions to use the registry, for instance (Which you should do if you
>want to be MS compliant....), without changing your code.
>...........................................................................
...

>How does one read the username from the [UserInfo]
>into variables, or the TOP,LEFT,BOTTOM coordinates
>from [Frame]?

>How does one change these entries?

>How does one add new entries to this INI file?

> Thanks,
> Magic



Sun, 24 Jun 2001 03:00:00 GMT  
 How to Read/Write to INI FIle

Quote:

> I think I might make this my sig

> Don't you ever read the posts in here. This question has been hashed over at
> least a dozen times over the last two weeks alone. Reset your news reader
> and start reading, instead of posting just to see your name.

Thanks for your help Todd.  I read all these post and found none that
would explain (examples) how to do what I asked.  I'll keep trying!

                                Magic



Sun, 24 Jun 2001 03:00:00 GMT  
 How to Read/Write to INI FIle
Hello  

If using an external ActiveX Dll is not overkill then
you can use my FileProcess.dll at
http://www.bcsupernet.com/users/Murray/vbhomepage/fileprocess/index.htm
260+ functions for file, directory, drive, system, internet
operations. Win95 and Nt systems.

Best wishes, Murray

' Get the Value from an Ini file given the section and keyword
        Dim myFile as New clFile
        myFile = "c:\temp\anyfile.ini"
        MsgBox myFile.GetIniValue "Section1", "Key1"

' Set the Value of an Ini file given the section and keyword and value
        Dim myFile as New clFile
        myFile = "c:\temp\anyfile.ini"
        myFile.SetIniValue "Section1", "Key1" , "Value1"

' Get all the Section Headers in an Ini file
' Returned into a Collection
' The total length must be <= 10000 chars
        Dim myCollection as New collection
        Dim myFile as New clFile
        myFile = "c:\windows\system.ini"
        myFile.GetIniSectionHeaders myCollection
        For each x in myCollection
                List1.AddItem x
        Next

' Get an entire Section of an Ini file
' Returned into two collections, keys and values
' The total length must be <= 32767 chars
    Dim myFile as New clFile
    Dim keys As New Collection
    Dim values As New Collection
    Dim section as string
    section = "boot"
    myFile = WindowsDirectory & "\system.ini"
    myFile.GetIniSection section, keys, values
    If keys.Count = 0 Then MsgBox "no entries"
    For i = 1 To keys.Count
      List2.AddItem keys(i) & " === " & values(i)
    Next

' Write an entire Section of an Ini file
' Passed in two collections, keys and values
' The total length must be <= 32767 chars
    Dim myFile as New clFile
    Dim keys As New Collection
    Dim values As New Collection
    Dim section as string
    section = "NewSection"
    myFile = WindowsDirectory & "\system.ini"
    myFile.WriteIniSection section, keys, values
    myFile.Edit

' Delete an entire Section of an Ini file
    Dim myFile as New clFile
    Dim section as string
    section = "OldSection"
    myFile = WindowsDirectory & "\system.ini"
    myFile.DeleteIniSection section
    myFile.Edit

' Flush Ini memory Cache to disk.
' If a program crashes before you flush the changes
' could be lost.
        Dim myFile as New clFile
        myFile = "c:\temp\anyfile.ini"
        myFile.SetIniFlush



Sun, 24 Jun 2001 03:00:00 GMT  
 How to Read/Write to INI FIle
You might want to take a look at these API's (among others)

GetPrivateProfileString
WritePrivateProfileString

Andr

Quote:

>Below is an .INI file for R&R Report Writer.
>Could someone please post the code to retrieve
>parts of this file and also to write new data to it.
>...........................................................................
...
>[Export]
>Export1=Excel PivotTable, RRXTAB.DLL
>Export2=Excel Chart, RRXCHART.DLL
>[Defaults]
>ProgDir32=D:\Program Files\R&R Report Writer\
>TemplateDir=D:\Program Files\R&R Report Writer\Template
>[Data Dictionary]
>DataDict=D:\Program Files\R&R Report Writer\Sample\rrdict.dbf
>DataDictIndex=D:\Program Files\R&R Report Writer\Sample\rrdict.ndx
>[User Info]
>UserName=Wakanla TwoBears
>Company=Parkway Hospital
>[Frame]
>Show=1
>Left=44
>Top=44
>Right=644
>Bottom=455
>[Save List]
>BandWidth=80
>ActionBar=1
>FormatBar=1
>FieldNames=0
>PasteArgs=1
>ShHzRul=1
>ShVtRul=1
>ShGrd=1
>ShowCalcComment=1
>IVer=2
>CloseInsDlg=0
>...........................................................................
...

>I received this example from a NG but don't really know
>how to use it.

>...........................................................................
..
>Declare the following API calls:

>Declare Function GetPrivateProfileStringA Lib "kernel32.dll" (ByVal
>inisection As String, ByVal inientry As String, ByVal returndefault As
>String, ByVal inientrystring As String, ByVal inientrysize As Integer,
>ByVal inifilename As String) As Integer

>Declare Function WritePrivateProfileStringA Lib "kernel32.dll" (ByVal
>inisection As String, ByVal inentry As String, ByVal inientrystring As
>String, ByVal lpFileName As String) As Integer

>For simplicity sake, define the following two functions:

>Function getinidata(section As String, keyword As String) As String
>'--------------------------------------------------
>' Calls the windows API to get values from trs.ini file
>' Returns data
>'--------------------------------------------------

>Dim length, returned$

>getinidata = ""
>If section <> "" And keyword <> "" Then
>    returned$ = Space$(256)
>    length = GetPrivateProfileStringA(section, keyword, "0", returned$,
>256, windir$ & "trs.ini")
>    returned$ = Left$(returned$, length)
>    getinidata = returned$
>End If

>End Function

>Function setinidata(ByVal section As String, ByVal keyword As String,
>ByVal inidata As Variant) As Variant

>'--------------------------------------------------
>' Calls the windows API to set values in trs.ini file
>' returns origional value
>'--------------------------------------------------

>Dim retvalue, inistring$
>setinidata = ""

>If section <> "" And keyword <> "" Then
>    inistring$ = LTrim$(inidata)
>    retvalue = WritePrivateProfileStringA(section, keyword, inistring$,
>windir$ & "trs.ini")
>    If retvalue <> 0 Then setinidata = inidata
>End If

>End Function

>In your code, refer to these two by simply using the section and
>parameter:
>E.g.:
>nrMRUs% = getinidata("MRUFiles", "Number")
>If setinidata("MRUFiles", "order", neworder$) <> neworder$ Then Msgbox
>"Error writing .ini file"

>In this way, you can later update your getinidata() and setinidata()
>functions to use the registry, for instance (Which you should do if you
>want to be MS compliant....), without changing your code.
>...........................................................................
...

>How does one read the username from the [UserInfo]
>into variables, or the TOP,LEFT,BOTTOM coordinates
>from [Frame]?

>How does one change these entries?

>How does one add new entries to this INI file?

> Thanks,
> Magic



Sun, 24 Jun 2001 03:00:00 GMT  
 How to Read/Write to INI FIle
Your question wasn't about 'How can you do something?' It was more like a
command to do it for you.

Quoted from your message...
"Below is an .INI file for R&R Report Writer.
Could someone please post the code to retrieve
parts of this file and also to write new data to it."

Apparently you wanted some one to put your variable names in the code where
it would run for you without any work on your part.

Also Quoted from your message...
"I received this example from a NG but don't really know
how to use it."

Why didn't you just post back to the thread you pasted the code from?
Don't be bashful, if you see a thread that follows the basic situation you
have, then post your question to the thread. Your question is more likely to
get answered there than to start a new thread asking the same basic
question. Don't expect the thread to be covering exactly what you want to
know about before you ask.

The rest of your questions have all been answered, just not with your exact
variable names, section names, or values.

Yes, I know I could have just answered your questions, or even edited the
code for you, or even ignored your post, but I'm tired of the repeated
questions. Especially from someone who has an example right in front of him.



Mon, 25 Jun 2001 03:00:00 GMT  
 How to Read/Write to INI FIle

Quote:

> Your question wasn't about 'How can you do something?' It was more like a
> command to do it for you.

Dear Todd,
I'm sorry if you took my request for a demand.  I said "could someone
post an example".  It WAS a request.  Not a demand!  Anyway, I've
received many responses to my request for help in understanding this
matter from well intended professionals in this and other NGs.
No need for you to waste your valuable time with my questions from
now on.

                        Thanks for your response,

                                        Magic



Mon, 25 Jun 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. How to read/write to ini file on a network?

2. Read/Write INI Files w/Access 7.0

3. Ini-file, read write and empty lines.

4. Reading and writing from and to ini files

5. read/write an .ini file

6. Reading and writing to an INI file?

7. Reading and Writing to .ini files - help please.

8. Read and Write to INI files

9. Reading/writing to an INI file

10. Reading / Writing an INI file

11. Reading / Writing an INI file

12. How to read and write an ini file with Qbasic 4.5

 

 
Powered by phpBB® Forum Software