Results 1 to 4 of 4

Thread: Writing to an ini file

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Birmingham
    Posts
    9

    Question Writing to an ini file

    IS there an easy way to write a whole section to an ini file?

    The code i have is

    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

    retval = WritePrivateProfileString("ICM", "TransportDriver", "TCP/IP", "C:\_custom\appsrv.ini")

    which will write "TransportDriver=TCP/IP" to the 'ICM' section in the ini file...I have about 23 values that I need to add to the 'ICM' section..is there an easy way to write multiple values to the same section in a ini file?

    I am only a newbie, so apologies if this is a basic question.

  2. #2
    Fanatic Member seec77's Avatar
    Join Date
    Jan 2003
    Posts
    596

    i have a solution

    here is a code i got from psc:

    VB Code:
    1. 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
    2. 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
    3.  
    4. Public Function GetFromINI(Section As String, Key As String, Directory As String) As String
    5. Dim strBuffer As String
    6. strBuffer = String(750, Chr(0))
    7. Key$ = LCase$(Key$)
    8. GetFromINI$ = Left(strBuffer, GetPrivateProfileString(Section$, ByVal Key$, "", strBuffer, Len(strBuffer), Directory$))
    9. End Function
    10.  
    11. Public Sub WriteToINI Section As String, Key As String, KeyValue As String, Directory As String
    12. Call WritePrivateProfileString(Section$, Key$, KeyValue$, Directory$)
    13. End Sub
    syntax=WriteToINI("ICM","TransportDriver","TCP/IP",app.path+"\INIFile.ini")

    syntax=msgbox GetFromINI("ICM","TransportDriver",app.path+"\INIFile.ini")

    you can write a bunch of keys to the same section by using different key names... here is an example of an ini file for one of my progs:

    [General]
    MainOptions="10,10,12"
    TenthMainOptionName="0,0,10"
    Best Regards,
    seec77

    If you helped me, cosinder yourself thanked.

    Get each and every Garfield strip here!
    Here you can get all Calvin & Hobes strips!
    Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!

    I am 33% addicted to Counterstrike. What about you?
    I am 23% addicted to Star Wars. What about you?
    I am 0% addicted to Tupac. What about you?

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Birmingham
    Posts
    9
    What I need to do is add all the below to the [ICM] section in the ini file:-

    [iCM]
    TransportDriver=TCP/IP
    BrowserProtocol=UDP
    Password=xxxxxxxx
    DesiredHRES=4294967295
    DesiredVRES=4294967295
    ScreenPercent=0
    DoNotUseDefaultCSL=Off
    Description=iCM
    Address=iCM
    InitialProgram=#iCM
    IconPath=C:\_custom\iCM.ico
    IconIndex=1
    ConnectType=1
    MaximumCompression=Off
    Compress=On
    PersistentCacheEnabled=Off
    MouseTimer=0
    KeyboardTimer=0
    AudioBandwidthLimit=1
    UseDefaultSound=On
    DefaultSoundType=1
    UseDefaultEncryption=On
    EncryptionLevel=1

  4. #4
    Fanatic Member seec77's Avatar
    Join Date
    Jan 2003
    Posts
    596

    Exclamation what's the problem?

    use the code i gave ya and write something like this:
    VB Code:
    1. WriteToINI("ICM","TransportDriver","TCP/IP",app.path+"\INIFile.ini")
    2. WriteToINI("ICM","BrowserProtocol","UDP",app.path+"\INIFile.ini")
    3. WriteToINI("ICM","Password","xxxxxxx",app.path+"\INIFile.ini")
    and so on...
    Best Regards,
    seec77

    If you helped me, cosinder yourself thanked.

    Get each and every Garfield strip here!
    Here you can get all Calvin & Hobes strips!
    Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!

    I am 33% addicted to Counterstrike. What about you?
    I am 23% addicted to Star Wars. What about you?
    I am 0% addicted to Tupac. What about you?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width