Results 1 to 3 of 3

Thread: hi how i can make ini file to my program

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    13

    Unhappy hi how i can make ini file to my program

    hi,

    hi how i can make ini file to my program to save the options in it.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You need to use API calls.

    Code:
    Private 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
    
    Private 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
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    as RobDog said... then you can use them like this

    VB Code:
    1. Option Explicit
    2. Private Declare Function GetPrivateProfileString _
    3. Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal _
    4. lpApplicationName As String, ByVal lpKeyName As String, _
    5. ByVal lpDefault As String, ByVal lpReturnedString As _
    6. String, ByVal nSize As Long, ByVal lpFileName As String) As _
    7. Long
    8.  
    9. Private Declare Function WritePrivateProfileString _
    10. Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal _
    11. lpApplicationName As String, ByVal lpKeyName As Any, ByVal _
    12. lpString As Any, ByVal lpFileName As String) As Long
    13.  
    14.  
    15.  
    16. Private Function ReadINI(strsection As String, strkey As String, strfullpath As String) As String
    17.    Dim strbuffer As String
    18.    Let strbuffer$ = String$(750, Chr$(0&))
    19.    Let ReadINI$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
    20. End Function
    21.  
    22. Private Sub WriteINI(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String)
    23.     Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$)
    24. End Sub
    25.  
    26. Private Sub Command1_Click()
    27.     'creates Test.ini that look like this:
    28.     '[DBParam]
    29.     'DBNAME=C:\myapp\db\mydb.mdb
    30.     '[Temp]
    31.     'TMPPATH=C:\myapp\tmp
    32.     WriteINI "DBParam", "DBName", "C:\myapp\db\mydb.mdb", "C:\TEST.INI"
    33.     WriteINI "Temp", "TMPPath", "C:\myapp\tmp", "C:\TEST.INI"
    34. End Sub
    35.  
    36. Private Sub Command2_Click()
    37.     'reading the settings saved above :-)
    38.     MsgBox ReadINI("DBParam", "DBName", "C:\TEST.INI")
    39.     MsgBox ReadINI("Temp", "TMPPath", "C:\TEST.INI")
    40. End Sub
    41.  
    42. Private Sub Command3_Click()
    43.     'Deletes the DBNAME key entierly
    44.     'so that the ini looks like this:
    45.     '[DBParam]
    46.     '[Temp]
    47.     'TMPPATH=C:\myapp\tmp
    48.     WriteINI "DBParam", "DBName", vbNullString, "C:\TEST.INI"
    49. End Sub
    -= a peet post =-

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