Sign in to follow this  
Followers 0
chssoccer

New Line in .ini file

3 posts in this topic

How do I read after the last key in an ini and then go to the next line after the key so I can continue writing my ini keys and values. I want it to look like this:

[section]
Key=1,2,3
NewKey=4,5,6


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                        





(adsbygoogle = window.adsbygoogle || []).push({});




                    
                
                    
                    
                    






    
    
        
GEOSoft   

    
        
    
             63
    
        
    

        
            
                Sure I'm senile. What's your excuse?
            
            

            
                

    
        
    

            
            MVPs
            
                
            
            
                

    
        
    
             63
    
        
    

                10,348 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #2 · 
            Posted 
            
            
            
        
    

    


            
        
            First off your example hows 2 sections 1 which is unused.  I'm thinking that was just a mistake in the post and you were really trying to create a code box.  To create an entry you just do another IniWrite()  Not that if you choose No to the first Msg boxbelow then A new Section and a new Key are created
$Ini= @ScriptDir & "\my.ini"
If FileExists($Ini) Then FileDelete($Ini);; You will not likely be using this line in actual code
IniWrite($Ini, "Section", "Key", "1,2,3")
If MsgBox ( 36, 'TEST', 'Are you ready to create the NewKey entry?') = 6 Then
   IniWrite($Ini, "Section", "NewKey", "4,5,6")
Else
   IniWrite($Ini, "Section2", "ThirdKey", "7,8,9")
   MsgBox ( 64, 'TEST', 'You chose No in the last msgbox so a ThirdKey entry was created in a new section instead.', 2)
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

It will go to the next line all by itself..

But to find the information in the INI you'll need a fiarly simple loop for read sections but to read the whole INI its a little more complex

This is an example of a whole INI being read to a treeview, which I don't think you will really understand

#NoTrayIcon
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)  ;calls the classic theme
#include <guitreeview.au3>
#include <guiconstants.au3>
Global $Skin_bk = 0x00000
Global $Skin_txt = 0x00ffcc
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("To Do", 414, 268, -1, -1, $WS_SIZEBOX, $WS_EX_TOOLWINDOW)
Global $TreeView = GUICtrlCreateTreeView(0, 0, 409, 245)
GUISetBkColor($skin_bk)
GUICtrlSetBkColor(-1,$Skin_bk)
GuiCtrlSetColor(-1,$Skin_txt)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Ini_To_Treeview(@ScriptDir & '\TO_DO.ini',$treeview)
For $i = 0 to 20000
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
Next

    Func Ini_TO_Treeview($ld_val, $Treeview1, $Progress = '0' )
    _GUICtrlTreeViewDeleteAllItems( $TreeView1 )
    GuiCtrlSetState( $Treeview1, $GUI_Show )
    Global $secs = IniReadSectionNames( $ld_val )
    If IsArray( $secs ) Then
    If $progress = '1' then ProgressOn( "Reading INI 2 Treeview", "Working..." )
    $total = $secs[0]
    Dim $a[999]
    For $i = 1 to $secs[0]-1 step 1
        $a[$i] = GUICtrlCreateTreeViewItem( $secs[$i], $TreeView1 )
        _GUICtrlTreeViewSetIcon( $treeview, -1, 'C:\windows\system32\shell32.dll', 165 )
        $b = IniReadSection( $ld_val, $secs[$i] )
        If @error <> 1 Then
        For $c = 1 to $b[0][0] step 1
            GUICtrlCreateTreeViewItem( $b[$c][1], $a[$i] )
            _GUICtrlTreeViewSetIcon( $treeview, -1, 'C:\windows\system32\shell32.dll', 110 )
        Next
        Endif
    If $progress = '1' then ProgressSet( (($i/$total)*100)-1, "Reading INI 2 Treeview", "Placing into a Treeview" )
    Next
    Endif
    ProgressOff()
    EndFunc

This will only work in 3.2.8.0

But if you just want to read a section like all data under [section_name] then you need to look at the help file under IniReadSection PM me if you still have trouble after that


[center][/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0