Sign in to follow this  
Followers 0
Tiboi

help needed with iniwrite please

23 posts in this topic

how can i get this code to auto incriment the number each time i save the info that gets put in.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Global $Demo,$txtBrowse,$btnBrowse,$txtName,$txtAddress,$btnAdd,$cboAddress,$btnSave,$btnGO,$nMsg

Main()

Func Main()
   ;Global $Demo,$txtBrowse,$btnBrowse,$txtName,$txtAddress,$btnAdd,$cboAddress,$btnGO,$nMsg
    $Demo = GUICreate("Demo", 623, 442, 385, 131)
    $txtBrowse = GUICtrlCreateInput("Browse", 0, 0, 321, 21)
    $btnBrowse = GUICtrlCreateButton("Browse", 328, 0, 75, 25)
    $txtName = GUICtrlCreateInput("Name", 0, 48, 209, 21)
    $txtAddress = GUICtrlCreateInput("Address", 0, 72, 209, 21)
    $btnAdd = GUICtrlCreateButton("Add", 64, 104, 75, 25)
    $cboAddress = GUICtrlCreateCombo("Select Address", 0, 160, 209, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $btnSave = GUICtrlCreateButton("Save", 232, 160, 91, 25)
    $btnGO = GUICtrlCreateButton("GO", 328, 216, 75, 25)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
             Case $btnAdd
                AddInfo()
        EndSwitch
    WEnd
EndFunc   ;==>Main

Func AddInfo()
    Local $Name = GUICtrlRead($txtName)
    Local $Address = GUICtrlRead($txtAddress)
    If $Name <> "" Or $Address <> "" Then
        IniWrite(@ScriptDir & "\Config.ini", "Names", "1", $Name) ;<-- i want this number to auto inccrease each time i save info from the form
        IniWrite(@ScriptDir & "\Config.ini", "Address", "1", $Address) ;<-- i want this number to auto inccrease each time i save info from the
    Else
    EndIf
 EndFunc   ;==>AddInfo

Share this post


Link to post
Share on other sites



If you need just number increase, then you could use something like that:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Global $Demo,$txtBrowse,$btnBrowse,$txtName,$txtAddress,$btnAdd,$cboAddress,$btnSave,$btnGO,$nMsg
Global $i = 0

Main()

Func Main()
   ;Global $Demo,$txtBrowse,$btnBrowse,$txtName,$txtAddress,$btnAdd,$cboAddress,$btnGO,$nMsg
    $Demo = GUICreate("Demo", 623, 442, 385, 131)
    $txtBrowse = GUICtrlCreateInput("Browse", 0, 0, 321, 21)
    $btnBrowse = GUICtrlCreateButton("Browse", 328, 0, 75, 25)
    $txtName = GUICtrlCreateInput("Name", 0, 48, 209, 21)
    $txtAddress = GUICtrlCreateInput("Address", 0, 72, 209, 21)
    $btnAdd = GUICtrlCreateButton("Add", 64, 104, 75, 25)
    $cboAddress = GUICtrlCreateCombo("Select Address", 0, 160, 209, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $btnSave = GUICtrlCreateButton("Save", 232, 160, 91, 25)
    $btnGO = GUICtrlCreateButton("GO", 328, 216, 75, 25)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
             Case $btnAdd
                AddInfo()
        EndSwitch
    WEnd
EndFunc   ;==>Main

Func AddInfo()
    Local $Name = GUICtrlRead($txtName)
    Local $Address = GUICtrlRead($txtAddress)
    If $Name <> "" Or $Address <> "" Then
        IniWrite(@ScriptDir & "\Config.ini", "Names", $i, $Name) ;<-- i want this number to auto inccrease each time i save info from the form
        IniWrite(@ScriptDir & "\Config.ini", "Address", $i, $Address) ;<-- i want this number to auto inccrease each time i save info from the
        $i += 1
    EndIf
 EndFunc   ;==>AddInfo

Share this post


Link to post
Share on other sites

If you need just number increase, then you could use something like that:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Global $Demo,$txtBrowse,$btnBrowse,$txtName,$txtAddress,$btnAdd,$cboAddress,$btnSave,$btnGO,$nMsg
Global $i = 0

Main()

Func Main()
   ;Global $Demo,$txtBrowse,$btnBrowse,$txtName,$txtAddress,$btnAdd,$cboAddress,$btnGO,$nMsg
    $Demo = GUICreate("Demo", 623, 442, 385, 131)
    $txtBrowse = GUICtrlCreateInput("Browse", 0, 0, 321, 21)
    $btnBrowse = GUICtrlCreateButton("Browse", 328, 0, 75, 25)
    $txtName = GUICtrlCreateInput("Name", 0, 48, 209, 21)
    $txtAddress = GUICtrlCreateInput("Address", 0, 72, 209, 21)
    $btnAdd = GUICtrlCreateButton("Add", 64, 104, 75, 25)
    $cboAddress = GUICtrlCreateCombo("Select Address", 0, 160, 209, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $btnSave = GUICtrlCreateButton("Save", 232, 160, 91, 25)
    $btnGO = GUICtrlCreateButton("GO", 328, 216, 75, 25)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
             Case $btnAdd
                AddInfo()
        EndSwitch
    WEnd
EndFunc   ;==>Main

Func AddInfo()
    Local $Name = GUICtrlRead($txtName)
    Local $Address = GUICtrlRead($txtAddress)
    If $Name <> "" Or $Address <> "" Then
        IniWrite(@ScriptDir & "\Config.ini", "Names", $i, $Name) ;<-- i want this number to auto inccrease each time i save info from the form
        IniWrite(@ScriptDir & "\Config.ini", "Address", $i, $Address) ;<-- i want this number to auto inccrease each time i save info from the
        $i += 1
    EndIf
 EndFunc   ;==>AddInfo

really that easy? you put me to shame. :mellow: thanks a lot

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

i add this to the code to populate the combo box. i want only the addresses in the combobox from the ini but i get a "ERROR: IniRead() [built-in] called with wrong number of args." can someone please help me with where i m going wrong?

Func Populate_CBOBox()
    Local $Address = IniRead(@ScriptDir & "\Config.ini", "Address", $i)
    GUICtrlSetData($cboAddress, $i & "|")
    $i += 1
EndFunc
Edited by Tiboi

Share this post


Link to post
Share on other sites

If you need just number increase, then you could use something like that:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Global $Demo,$txtBrowse,$btnBrowse,$txtName,$txtAddress,$btnAdd,$cboAddress,$btnSave,$btnGO,$nMsg
Global $i = 0

Main()

Func Main()
   ;Global $Demo,$txtBrowse,$btnBrowse,$txtName,$txtAddress,$btnAdd,$cboAddress,$btnGO,$nMsg
    $Demo = GUICreate("Demo", 623, 442, 385, 131)
    $txtBrowse = GUICtrlCreateInput("Browse", 0, 0, 321, 21)
    $btnBrowse = GUICtrlCreateButton("Browse", 328, 0, 75, 25)
    $txtName = GUICtrlCreateInput("Name", 0, 48, 209, 21)
    $txtAddress = GUICtrlCreateInput("Address", 0, 72, 209, 21)
    $btnAdd = GUICtrlCreateButton("Add", 64, 104, 75, 25)
    $cboAddress = GUICtrlCreateCombo("Select Address", 0, 160, 209, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $btnSave = GUICtrlCreateButton("Save", 232, 160, 91, 25)
    $btnGO = GUICtrlCreateButton("GO", 328, 216, 75, 25)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
             Case $btnAdd
                AddInfo()
        EndSwitch
    WEnd
EndFunc   ;==>Main

Func AddInfo()
    Local $Name = GUICtrlRead($txtName)
    Local $Address = GUICtrlRead($txtAddress)
    If $Name <> "" Or $Address <> "" Then
        IniWrite(@ScriptDir & "\Config.ini", "Names", $i, $Name) ;<-- i want this number to auto inccrease each time i save info from the form
        IniWrite(@ScriptDir & "\Config.ini", "Address", $i, $Address) ;<-- i want this number to auto inccrease each time i save info from the
        $i += 1
    EndIf
 EndFunc   ;==>AddInfo

i have a problem with this. everytime i run the script and add some info it overwrites the previous data stored alredy. i need it to append to the alredy stored data. say if number 1,2,4,5,10 is already stored, i want it to fill in the missing numbers so when it stores again it will store to 3 then 6 instead of 11,12 and so on

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

i tried this but still don't work any help please

Func Populate_CBOBox()
    Local $iMax, $data, $i
    Local $Address = IniRead(@ScriptDir & "\Config.ini", "Address", $i & "|", "Default")
    Local $arr = StringSplit($data, "|")
    If IsArray($arr) Then
        For $i = 1 To $arr[0]
            GUICtrlSetData($cboAddress, $arr[$i] & @LF)
        Next
    EndIf
EndFun
Edited by Tiboi

Share this post


Link to post
Share on other sites

I really didnt get what are you trying to do but i hope that helps. It gets number of Names in Ini file and adds +1.

Func AddInfo()
    $x=IniReadSection(@ScriptDir & "\Config.ini", "Names")
    $i=$x[0][0]
    Local $Name = GUICtrlRead($txtName)
    Local $Address = GUICtrlRead($txtAddress)
    If $Name <> "" Or $Address <> "" Then
        IniWrite(@ScriptDir & "\Config.ini", "Names", $i+1, $Name) ;<-- i want this number to auto inccrease each time i save info from the form
        IniWrite(@ScriptDir & "\Config.ini", "Address", $i+1, $Address) ;<-- i want this number to auto inccrease each time i save info from the
    Else
    EndIf
 EndFunc   ;==>AddInfo

Share this post


Link to post
Share on other sites

I really didnt get what are you trying to do but i hope that helps. It gets number of Names in Ini file and adds +1.

Func AddInfo()
    $x=IniReadSection(@ScriptDir & "\Config.ini", "Names")
    $i=$x[0][0]
    Local $Name = GUICtrlRead($txtName)
    Local $Address = GUICtrlRead($txtAddress)
    If $Name <> "" Or $Address <> "" Then
        IniWrite(@ScriptDir & "\Config.ini", "Names", $i+1, $Name) ;<-- i want this number to auto inccrease each time i save info from the form
        IniWrite(@ScriptDir & "\Config.ini", "Address", $i+1, $Address) ;<-- i want this number to auto inccrease each time i save info from the
    Else
    EndIf
 EndFunc   ;==>AddInfo

with this when i run the scripe it exits

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

ok this is the whole script. i would like for it to save the info to the next free number. say when you open the ini you see 0=bla|1=bla|2=bla|4=bla, i want when i open the app anain the next time and save it will save to number 3=bla instead of moving on to 5=bla or overwriting 0=bla like it is doing right now.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Global $Demo, $txtBrowse, $btnBrowse, $txtName, $txtAddress, $btnAdd, $cboAddress, $btnSave, $btnGO, $nMsg, $btnRemove
Global $w = 0

Main()

Func Main()
    ;Global $Demo,$txtBrowse,$btnBrowse,$txtName,$txtAddress,$btnAdd,$cboAddress,$btnGO,$nMsg
    $Demo = GUICreate("Demo", 623, 442, 385, 131)
    $txtBrowse = GUICtrlCreateInput("Browse", 0, 0, 321, 21)
    $btnBrowse = GUICtrlCreateButton("Browse", 328, 0, 75, 25)
    $txtName = GUICtrlCreateInput("Name", 0, 48, 209, 21)
    $txtAddress = GUICtrlCreateInput("Address", 0, 72, 209, 21)
    $btnAdd = GUICtrlCreateButton("Add", 64, 104, 75, 25)
    $cboAddress = GUICtrlCreateCombo("Select Address", 0, 160, 209, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $btnRemove = GUICtrlCreateButton("Remove", 232, 160, 91, 25)
    $btnGO = GUICtrlCreateButton("GO", 328, 216, 75, 25)
    ;Populate_CBOBox()
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btnAdd
                AddInfo()
        EndSwitch
    WEnd
EndFunc   ;==>Main

Func AddInfo()
    Local $Name = GUICtrlRead($txtName)
    Local $Address = GUICtrlRead($txtAddress)
    If $Name <> "" Or $Address <> "" Then
        IniWrite(@ScriptDir & "\Config.ini", "Names", $w, $Name) ;<-- i want this number to auto inccrease each time i save info from the form
        IniWrite(@ScriptDir & "\Config.ini", "Address", $w, $Address) ;<-- i want this number to auto inccrease each time i save info from the
        $w += 1
    EndIf
EndFunc
Edited by Tiboi

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

So just load value of $i to ini before closing your soft and right after you launched it, read it from ini, so it would know that it should start count from 5 or any other number, not from 0.

So that means you could use something like this:

Case $GUI_EVENT_CLOSE
     IniWrite(@ScriptDir & "\Config.ini", "Value", "i", $i)
     Exit

And at the begining of script this:

$i = IniRead(@ScriptDir & "\Config.ini", "Value", "i", "0")
Edited by Makaule

Share this post


Link to post
Share on other sites

This won't do exactly what you asked but it should re-order everything and then add the new entry to the bottom of the section. There is a somewhat more complex method that pops to mind to get exactly what you asked for but this is probably the easier way to go. Warning, this is untested, just written on the fly.

$sIni = @ScriptDir & "\Config.ini"
$aSec_names = FileReadSection($sIni, "Names")
$aSec_Addr = FileReadSection($sIni, "Address")

If IniDelete($sIni, "Names") AND IniDelete($sIni, "Address") Then
    $iUbound = Ubound($aSec_names) -1
    For $i = 1 To $iUbound
        IniWrite($sIni, "Names", $i-1, $aSec_names[$i][1])
        IniWrite($sIni, "Address", $i-1, $aSec_Addr[$i][1])
    Next
    IniWrite($sIni, "Names", $iUbound, "New Name")
    IniWrite($sIni, "Address", $iUbound, "New Address")
EndIf

Also note, that no matter what method you use, it will be imperative that the "Names" and "Address" sections contain the same number of items and in the proper order. Alternatly you could create a new 2 Dimension array from the 2 arrays created above and use that in the loop instead.


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

ok this is what i am trying to do.

1. user puts data into form and saves it to the ini file

2. that data is auto populated to the combobox when the app is run

3. user can select a name from the combobox dropdown and delete it and that action removes the name and address from the ini file.

now deleting a entry will leave an empty space. eg if there was 1=a|2=b|3=c and b is what got deleted then the ini file would read 1=a|3=c now i want when a name and address is saved again that it saves it to 2=b instead of 4=d or overwriting 1=a. understand?

Share this post


Link to post
Share on other sites

I realize that you will have an empty space when you delete an entry. So far all is good. What the code that I gave you does, is remove all the remaining entries and then re-write them starting at 0 and adds the new one to the bottom of the list. like I said, there is a more complex method whereby you would enumerate the Ini Sections looking for the first empty position. then write to that position. When you delete an entry, do you delete it entirely or just delete the data. If the latter is the case then the code I gave you will still work but you will have to put a conditional in there.

For $i = 1 To $iUbound
      If $aSec_Names[$i][1] <> "" Then
        IniWrite($sIni, "Names", $i-1, $aSec_names[$i][1])
        IniWrite($sIni, "Address", $i-1, $aSec_Addr[$i][1])
      EndIf
    Next

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

I realize that you will have an empty space when you delete an entry. So far all is good. What the code that I gave you does, is remove all the remaining entries and then re-write them starting at 0 and adds the new one to the bottom of the list. like I said, there is a more complex method whereby you would enumerate the Ini Sections looking for the first empty position. then write to that position. When you delete an entry, do you delete it entirely or just delete the data. If the latter is the case then the code I gave you will still work but you will have to put a conditional in there.

For $i = 1 To $iUbound
      If $aSec_Names[$i][1] <> "" Then
        IniWrite($sIni, "Names", $i-1, $aSec_names[$i][1])
        IniWrite($sIni, "Address", $i-1, $aSec_Addr[$i][1])
      EndIf
    Next

thank you very much I'll try to figure out what it does then include it i my code. cause i'm not that advance yet :mellow: i have yet to figure out arrays

Share this post


Link to post
Share on other sites

Scrap that. I've had a chance to test this one and it should do what you want as long as you are just deleting the values and not the keys.

$sIni = @ScriptDir & "\config.ini"
$aNames = IniReadSection($sIni, "Names")
$aAddress = IniReadSection($sIni, "Address")
$iSet = 0


$iUbound = UBound($aNames) - 1
For $i = 1 To $iUbound
    If $aNames[$i][1] = "" Then
        IniWrite($sIni, "Names", $i - 1, "New Name")
        IniWrite($sIni, "Address", $i - 1, "New Address")
        $iSet = 1
        ExitLoop
    EndIf
Next
If NOT $iSet Then
    IniWrite($sIni, "Names", $iUbound, "New Name")
    IniWrite($sIni, "Address", $iUbound, "New Address")
EndIf

If you are deleting the keys then we will take a different approach. Be sure to back up your Ini file before running code against it if the current contents are important to you.


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

thankyou GEOSoft for the above code.

can you please explain this code for me i wrote it but cant seem to understand how to make it give me the output i want. and i've read the arrays wiki but it does not explain the multi dimension arrays properly, so i'm still lost.

i want the output ini file to look like this:

[Names]

1=John

2=Phillip

[Address]

1=Dears land Bk.

2=L'Abayee

this is the code i wrote to save the ini:

Func AddInfo()
    Local $i, $Key
    Local $Name = GUICtrlRead($txtName)
    Local $Address = GUICtrlRead($txtAddress)
    Local $array[3][2] = [["[Name]", $Key, $Name],["[Address]", $Key, $Address]]
    For $i = 0 To UBound($array)
        ;ConsoleWrite($array[$i][0] & $array[0][1] & $array[0][1])
        IniWrite(@ScriptDir & "\Config.ini", $array[$i][0], $array[0][1], $array[0][2])
    Next
EndFunc

and this is the full demo app to test it:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Global $Demo, $txtBrowse, $btnBrowse, $txtName, $txtAddress, $btnAdd, $cboAddress, $btnSave, $btnGO, $nMsg, $btnRemove
Global $w = 0

Main()

Func Main()
    ;Global $Demo,$txtBrowse,$btnBrowse,$txtName,$txtAddress,$btnAdd,$cboAddress,$btnGO,$nMsg
    $Demo = GUICreate("Demo", 623, 442, 385, 131)
    $txtBrowse = GUICtrlCreateInput("Browse", 0, 0, 321, 21)
    $btnBrowse = GUICtrlCreateButton("Browse", 328, 0, 75, 25)
    $txtName = GUICtrlCreateInput("Name", 0, 48, 209, 21)
    $txtAddress = GUICtrlCreateInput("Address", 0, 72, 209, 21)
    $btnAdd = GUICtrlCreateButton("Add", 64, 104, 75, 25)
    $cboAddress = GUICtrlCreateCombo("Select Address", 0, 160, 209, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $btnRemove = GUICtrlCreateButton("Remove", 232, 160, 91, 25)
    $btnGO = GUICtrlCreateButton("GO", 328, 216, 75, 25)
    ;Populate_CBOBox()
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btnAdd
                AddInfo()
        EndSwitch
    WEnd
EndFunc   ;==>Main


Func AddInfo()
    Local $i, $Key
    Local $Name = GUICtrlRead($txtName)
    Local $Address = GUICtrlRead($txtAddress)
    Local $array[3][2] = [["[Name]", $Key, $Name],["[Address]", $Key, $Address]]
    For $i = 0 To UBound($array)
        ;ConsoleWrite($array[$i][0] & $array[0][1] & $array[0][1])
        IniWrite(@ScriptDir & "\Config.ini", $array[$i][0], $array[0][1], $array[0][2])
    Next
EndFunc

Share this post


Link to post
Share on other sites

That whole array is wrong and you do NOT use For $i = 0 To Ubound($array). It should be For $i = 0 To Ubound($array) -1

Also for section names you don'te include the "[" and "]"

To test an array, the best method is to use #include<array.au3> and then after the array has been created use _ArrayDisplay($array).

I'm not testing anything at the moment, it's been a long day, but I will check it later. On second thought here is some correction.

Func AddInfo()
    Local $i, $Key
    Local $Name = GUICtrlRead($txtName)
    Local $Address = GUICtrlRead($txtAddress)
    ;;I don't know where you are getting the value of $Key in the next line
    Local $array[2][3] = [["Name", $Key, $Name],["Address", $Key, $Address]];; you had the dimensions backwards
    _ArrayDisplay($array)
    Exit ;; Take this out after you see the array results.  Always test an array before assuming it's right
    For $i = 0 To UBound($array)
        ;ConsoleWrite($array[$i][0] & $array[0][1] & $array[0][1])
        IniWrite(@ScriptDir & "\Config.ini", $array[$i][0], $array[0][1], $array[0][2])
    Next
EndFunc

You could actually just use a variation of what I gave you. It puts the new values in the first blank spot and if there are no empty spots it adds them to the bottom. In this case there is no reason to use an additional Array.

Global $sIni = @ScriptDir & "\test.ini";; Put this line near the top of the script

;; When you are ready to call the function, use this
Local $sName = GUICtrlRead($txtName)
Local $sAddress = GUICtrlRead($txtAddress)
_AddRecord($sName, $sAddress)

Func _AddRecord($s_Name, $s_Address)
    Local $aNames = IniReadSection($sIni, "Name")
    Local $aAddress = IniReadSection($sIni, "Address")
    Local $iSet = 0
    $iUbound = UBound($aNames) - 1
    For $i = 1 To $iUbound
        If $aNames[$i][1] = "" Then
            IniWrite($sIni, "Name", $i - 1, $s_Name)
            IniWrite($sIni, "Address", $i - 1, $s_Address)
            $iSet = 1
            ExitLoop
        EndIf
    Next
    If NOT $iSet Then
        IniWrite($sIni, "Names", $iUbound, $s_Name
        IniWrite($sIni, "Address", $iUbound, $s_Address
    EndIf
EndFunc   ;==>_AddRecord

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

this is an updated addinfo() but it still does not work. any help appreciated even if is directing me to a source of info.

Func AddInfo()
    Local $var[2] = [GUICtrlRead($txtName), GUICtrlRead($txtAddress)]
    If $var <> 0 Then
        For $i = 1 To $var[0][0]
            IniWrite(@ScriptDir & "\Config.ini", $var[$i][0], $var[$i][1])
        Next
    Else
        MsgBox(48, "Error", "All info is required.")
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

this is an updated addinfo() but it still does not work. any help appreciated even if is directing me to a source of info.

Func AddInfo()
    Local $var[2] = [GUICtrlRead($txtName), GUICtrlRead($txtAddress)]
    If $var <> 0 Then
        For $i = 1 To $var[0][0]
            IniWrite(@ScriptDir & "\Config.ini", $var[$i][0], $var[$i][1])
        Next
    Else
        MsgBox(48, "Error", "All info is required.")
    EndIf
EndFunc

You can't write to 2 different sections with a single IniWrite() and you didn't tell it what section to write to nor did you tell it what key to write to. I gave you a corrected version of the array and I've already stated that there is no reason to create an extra array

What's wrong with the _AddRecord() Function I gave you. It solves your first problem of re-using a deleted entry and if there isn't one it just adds it to the end. Test it and see.

Copy and paste the following into an Ini file on your desktop. Name it Test.ini

[Name]

0=AB

1=BC

2=CD

3=

4=EF

5=FG

6=GH

7=HI

8=IJ

9=JK

[Address]

0=10

1=11

2=12

3=

4=14

5=15

6=16

7=17

8=18

9=19

Create a new AutoIt file on the desktop and use this code

Global $sIni = @ScriptDir & "\test.ini"

Local $sName = "Name"
Local $sAddress = "Address"
_AddRecord($sName, $sAddress)
ShellExecuteWait($sIni)
;; Read the change in the file. Name and Address should be at entry #3.  Close the file
$sName = "Next " & $sName
$sAddress = $Next " & $sAddress
_AddRecord($sName, $sAddress)
ShellExecute($sIni)
;; Read the file now.  The newest entries should be at the bottom (#10) because there were no available slots before that.

Func _AddRecord($s_Name, $s_Address)
    Local $aNames = IniReadSection($sIni, "Name")
    Local $aAddress = IniReadSection($sIni, "Address")
    Local $iSet = 0
    $iUbound = UBound($aNames) - 1
    For $i = 1 To $iUbound
        If $aNames[$i][1] = "" Then
            IniWrite($sIni, "Name", $i - 1, $s_Name)
            IniWrite($sIni, "Address", $i - 1, $s_Address)
            $iSet = 1
            ExitLoop
        EndIf
    Next
    If NOT $iSet Then
        IniWrite($sIni, "Names", $iUbound, "New Name")
        IniWrite($sIni, "Address", $iUbound, "New Address")
    EndIf
EndFunc   ;==>_AddRecord
Edited by GEOSoft

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

#20 ·  Posted (edited)

thanks man for the help. this the above code works. and its not that i dont use the previous one its that i don't understand how it works so i can't edit it to make it work with my script. cause i need the data saved in the ini to work with this function.

Func Populate_CBOBox()
    Local $var = IniReadSection(@ScriptDir & "\Config.ini", "Address")
    If @error Then
        GUICtrlSetData($cboAddress, "Can't find a valid INI file.")
    Else
        For $i = 1 To $var[0][0]
            GUICtrlSetData($cboAddress, $var[$i][1])
        Next
    EndIf
EndFunc

and when the combo-box is populated i want to be able to choose a user name or in the case of this script an address and press the delete button and that should delete the address and user name for that address.(maybe i should make the script re number the data left when it deletes an entry. what do you think)

Edited by Tiboi

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