Results 1 to 3 of 3

Thread: [VB6] INI file class (unicode aware)

  1. #1

    Thread Starter
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    [VB6] INI file class (unicode aware)

    'Mainly intended for caching data beetween read-write operations
    'Supports UTF-16 LE ini-files format
    'Provides wide range of methods
    'Doesn't support reading / saving commentary in ini file

    Based on Scripting.Dictionary, see also:
    #Const UseHashtable
    #Const UseStringBuilder

    Examples of using:
    Code:
    
    Option Explicit
    
    Private Sub Form_Load()
        Dim Item
    
        'init 
        Dim cIni As clsIniFile
        Set cIni = New clsIniFile
    
        'open ini file 
        cIni.InitFile App.Path & "\some.ini", 1200 '1200 - UTF16-LE or 1251 (ANSI), 0 - autodetect 
    
        'set case insensitive mode 
        cIni.CompareMethod = vbTextCompare
    
        'write (or overwrite): 
        '[Section1] 
        'Param1=Data1 
        'Param2=Data2 
        cIni.WriteParam "Section1", "Param1", "Data1"
        cIni.WriteParam "Section1", "Param2", "Data2"
    
        'create empty section 
        cIni.CreateSection "Section Empty1"
        cIni.CreateSection "Section Empty2"
    
        Debug.Print "Param1 = " & cIni.ReadParam("Section1", "Param1")
        Debug.Print "Number of parameters in Section1: " & cIni.CountParams("Section1")
        Debug.Print "Total sections: " & cIni.CountSections
    
        'does data 'Data1' exist in 'Section1' ? 
        Debug.Print "Data2 exists? " & cIni.ExistData("Section1", "Data2")
        Debug.Print "param2 exists? " & cIni.ExistParam("Section1", "param2")
    
        Debug.Print "Currently loaded filename is: " & cIni.FileName
    
        'search for parameter name, which holds a 'Data2' in 'Section1' 
        Debug.Print "Param name of 'Data2' is: " & cIni.GetParamNameByData("Section1", "Data2")
    
        'enum parameters' names 
        For Each Item In cIni.GetParamNames("Section1")
            Debug.Print Item
        Next
        'enum data in section 
        For Each Item In cIni.GetParamValues("Section1")
            Debug.Print Item
        Next
        'enum sections' names 
        For Each Item In cIni.GetSections
            Debug.Print Item
        Next
    
        'to remove a parameter 
        If cIni.RemoveParam("Section1", "Param2") Then Debug.Print "Param2 is removed successfully!"
    
        'to remove section 
        If cIni.RemoveSection("Section Empty2") Then Debug.Print "'Section Empty2' is removed successfully!"
    
        'to remove all sections (erase file) 
        'cIni.RemoveSectionsAll 
    
        'populate physical file (all cached data will by written to the disk) 
        cIni.Flush
    
        'when you finished work with the class 
        Set cIni = Nothing
    
        Unload Me
    End Sub
    
    
    Result:
    Param1 = Data1
    Number of parameters in Section1: 2
    Total sections: 3
    Data2 exists? True
    param2 exists? True
    Currently loaded filename is: H:\_AVZ\Íàøè ðàçðàáîòêè\_Dragokas\clsIniFile\some.ini
    Param name of 'Data2' is: Param2
    Param1
    Param2
    Data1
    Data2
    Section1
    Section Empty1
    Section Empty2
    Param2 is removed successfully!
    'Section Empty2' is removed successfully!
    Attached Files Attached Files
    Last edited by Dragokas; Jan 18th, 2021 at 05:44 PM.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  2. #2

    Thread Starter
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: [VB6] INI file class (unicode aware)

    Updated.

    Added index 0 as CodePage Id for .InitFile() - allowing class autodetect the codepage (UTF16 or ANSI)
    Added method .RenameParam()
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  3. #3
    Lively Member
    Join Date
    Sep 2016
    Posts
    94

    Re: [VB6] INI file class (unicode aware)

    Thank you so much.
    I use this class from a long time.

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