Jump to content

Recommended Posts

  • Moderators
Posted

Doctorkirk,

As I told you yesterday, you cannot have more than one section in an ini file with the same name - so of course you overwrite the existing data. I have been very busy with other things - I will try to find time to look at your problem this afternoon after I have watched the Grand Prix highlights. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

I know, i was trying to add a same-named section with the suffix "($k)" where $k start with 01 and goes on, maybe writing/reading it in a ini called config, that i need for the other part of the program..

  • Moderators
Posted

Doctorkirk,

Why not post what you tried: ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

I posted it on Page #3 then Nessie corrected me something wrong, but it doesn't work :/

btw, here's the interested piece of the code:

Case $cAdd
            $lol = GUICtrlRead($cApp) And GUICtrlRead($cUser) And GUICtrlRead($cPwd)
            If $lol = "" Then
                            MsgBox(16,"Tutti i campi sono vuoti","Scrivere almeno un campo")
                        Else
                            $bho = GUICtrlRead($cApp & " (" & $k & ")")
            $sData = GUICtrlRead($cApp)
            $aSections = IniReadSectionNames($sIni)
            For $i = 1 To $aSections[0]
                If $sData = $aSections[$i] Then
                    $cMsg = MsgBox(52, "Attenzione!", GUICtrlRead($cApp) & ' esiste già, aggiungerlo come"' & GUICtrlRead($cApp) & " (" & $k & ')"?')
                    If $cMsg = 1 Then
                        IniWrite($sIni, $bho, "name", GUICtrlRead($cUser))
                        IniWrite($sIni, $bho, "pswd", GUICtrlRead($cPwd))
                        _Load_Ini()
                        $k = $k + 01
                        IniWrite("config", "config", "k", $k)
                        ExitLoop ;<<<<<<<<<<<<<< All done here we can skip the loop (Nessie added this)
                    Else
                        GUISetState()
                        ExitLoop ;<<<<<<<<<<<<<<< Here is the problem! (and this)
                    EndIf
                Else
                    $sData = GUICtrlRead($cApp) & "|" & GUICtrlRead($cUser) & "|" & GUICtrlRead($cPwd)
                    If $sData <> "||" Then
                        IniWrite($sIni, GUICtrlRead($cApp), "name", GUICtrlRead($cUser))
                        IniWrite($sIni, GUICtrlRead($cApp), "pswd", GUICtrlRead($cPwd))
                        _Load_Ini()
                        For $i = $cApp To $cPwd
                            GUICtrlSetData($i, "")
            Next
        EndIf
    EndIf
    Next
    EndIf
    EndSwitch
WEnd

forgot,

$k = IniRead("config.ini", "config", "k", "Not Set")
  • Moderators
Posted

Doctorkirk,

Here is how I would implement an ini with numeric sections allowing multiple "App" lines: :)

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <Array.au3>

Global $sIni = "Test.ini"

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xC4C4C4)

$cListView = GUICtrlCreateListView("Section|App|Username|Password", 10, 10, 480, 300, Default, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetColumnWidth($cListView, 0, 0)
_GUICtrlListView_SetColumnWidth($cListView, 1, 155)
_GUICtrlListView_SetColumnWidth($cListView, 2, 155)
_GUICtrlListView_SetColumnWidth($cListView, 3, 155)

_Load_Ini()

GUICtrlCreateLabel("App", 200, 355, 100, 20)
GUICtrlCreateLabel("Username", 200, 395, 100, 20)
GUICtrlCreateLabel("Password", 200, 435, 100, 20)

$cApp = GUICtrlCreateInput("", 200, 370, 200, 20)
$cUser = GUICtrlCreateInput("", 200, 410, 200, 20)
$cPwd = GUICtrlCreateInput("", 200, 450, 200, 20)

$cAdd = GUICtrlCreateButton("Add", 10, 350, 80, 30)
$cDel = GUICtrlCreateButton("Delete", 10, 390, 80, 30)
$cMod = GUICtrlCreateButton("Modify", 10, 430, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cDel
            ; Read selected item
            $sItemText = GUICtrlRead(GUICtrlRead($cListView))
            ; Split into the different columns
            $aSplit = StringSplit($sItemText, "|")
            ; Delete the ini section
            IniDelete($sIni, $aSplit[1])
            ; Reload the ListView
            _Load_Ini()
        Case $cMod
            ; Read selected item
            $sItemText = GUICtrlRead(GUICtrlRead($cListView))
            ; Split into the different columns
            $aSplit = StringSplit($sItemText, "|")

            ; Place items in inputs
            GUICtrlSetData($cApp, $aSplit[2])
            GUICtrlSetData($cUser, $aSplit[3])
            GUICtrlSetData($cPwd, $aSplit[4])
            ; Change button name
            GUICtrlSetData($cMod, "Save")
            ; Now wait for the "Save" button
            While 1
                Switch GUIGetMsg()
                    Case $cMod
                        ; First delete the existing section
                        IniDelete($sIni, $aSplit[1])
                        ; Rename the button again
                        GUICtrlSetData($cMod, "Modify")
                        ; And now add the new data
                        ; Check we have something to add
                        $sData = GUICtrlRead($cApp) & "|" & GUICtrlRead($cUser) & "|" & GUICtrlRead($cPwd)
                        If $sData <> "||" Then
                            ; Add to the ini
                            IniWrite($sIni, $aSplit[1], "app", GUICtrlRead($cApp))
                            IniWrite($sIni, $aSplit[1], "name", GUICtrlRead($cUser))
                            IniWrite($sIni, $aSplit[1], "pswd", GUICtrlRead($cPwd))
                            ; Rewrite the ListView
                            _Load_Ini()
                            ; Clear the inputs
                            For $i = $cApp To $cPwd
                                GUICtrlSetData($i, "")
                            Next
                        EndIf
                        ; And continue
                        ExitLoop
                EndSwitch
            WEnd
        Case $cAdd
            ; Check we have something to add
            $sData = GUICtrlRead($cApp) & "|" & GUICtrlRead($cUser) & "|" & GUICtrlRead($cPwd)
            If $sData <> "||" Then
                ; Find the next available section
                $aSectionNames = IniReadSectionNames($sIni)
                ; Get into order
                _ArraySort($aSectionNames, 0, 1)
                ; Now look to see if there are any holes in the list
                For $i = 1 To $aSectionNames[0]
                    If Number($aSectionNames[$i]) <> $i Then
                        ; There is a hole - so fill it
                        ExitLoop
                    EndIf
                Next
                ; Either we found a hole or we need to add to the end of the list
                $sSection = StringFormat("%03i", $i)
                ; Add to the ini
                IniWrite($sIni, $sSection, "app", GUICtrlRead($cApp))
                IniWrite($sIni, $sSection, "name", GUICtrlRead($cUser))
                IniWrite($sIni, $sSection, "pswd", GUICtrlRead($cPwd))
                ; Rewrite the ListView
                _Load_Ini()
                ; Clear the inputs
                For $i = $cApp To $cPwd
                    GUICtrlSetData($i, "")
                Next
            EndIf
    EndSwitch

WEnd

Func _Load_Ini()
    ; Delete current contents
    _GUICtrlListView_DeleteAllItems($cListView)
    ; Read sections
    Local $aSections = IniReadSectionNames($sIni)
    ; Loop through sections
    For $i = 1 To $aSections[0]
        $sData = $aSections[$i]
        ; Add relevant sections to ListView data
        $sData &= "|" & IniRead($sIni, $aSections[$i], "app", "Not set")
        $sData &= "|" & IniRead($sIni, $aSections[$i], "name", "Not set")
        $sData &= "|" & IniRead($sIni, $aSections[$i], "pswd", "Not set")
        ; And add data to ListView
        GUICtrlCreateListViewItem($sData, $cListView)
    Next
EndFunc

Any questions? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

Doctorkirk,

I do not know and I am not going to piece together your script from several different posts to find out. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

No, the problematic part of the code is the one that i posted above, or rather, the thing that happen when i click "add", the problem is there, not on another part of the script...

Posted (edited)

Any questions? :)

yep, one, it's normal that when i delete/add the List shows me the records twice? o.O

Edit: Ok, sorry, my fault, i was not implementing the first part of the code :/ :P

Edited by Doctorkirk
  • Moderators
Posted

Doctorkirk,

Debugging the function you posted above in isolation is not possible as you have variables that must have been declared elsewhere. How am I supposed to know what they are and what value they should have? ;)

And I do not get double lines when I delete and add items. Give me a precise list of actions to obtain this result and post the ini file you started with. It should look something like this: :)

[001]
app= My Bank
name=www.some.url
pswd=my password
sec1=security question1
ans1=security question 1 answer
[002]
app=PC1
name=admin
pswd=admin password
[003]
app=User1
name=user1
pswd=user2 password
[004]
app=autoit
name=my user id
pswd=my password

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

And I do not get double lines when I delete and add items. Give me a precise list of actions to obtain this result and post the ini file you started with. It should look something like this: :)

Yeah, i forgot just to add the first part of the script modified :P

Here's the whole code, if you understand what's wrong please tell me, i think that's a little error because the first time i played with it at least the "warning" MsgBox was appearing...

#include 
#include 
#include 

Global $sIni = "Test.ini", $k = IniRead("config.ini","config","k","Not Set"), $count

;~ Spazio per la GUI di Login;

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xC4C4C4)

$cListView = GUICtrlCreateListView("App|Username|Password", 10, 190, 480, 300, Default, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetColumnWidth($cListView, 0, 155)
_GUICtrlListView_SetColumnWidth($cListView, 1, 155)
_GUICtrlListView_SetColumnWidth($cListView, 2, 155)

_Load_Ini()
GUICtrlCreateLabel("App:", 15, 69, 100, 20)
GUICtrlCreateLabel("Username:", 184, 69, 100, 20)
GUICtrlCreateLabel("Password:", 350, 69, 100, 20)
GUICtrlCreateLabel("Search:",325,8,36,20)

$cSearch = GUICtrlCreateInput("",365,5,110,20)
GUICtrlSetTip(-1,"Scrivi nome App che vuoi cercare")
$cApp = GUICtrlCreateInput("", 14, 85, 130, 20)
$cUser = GUICtrlCreateInput("", 183, 85, 130, 20)
$cPwd = GUICtrlCreateInput("", 349, 85, 130, 20)

;~ $bFetch = GUICtrlCreateButton("Vis.", 10, 310, 80, 30)
$cAdd = GUICtrlCreateButton("Add", 10, 145, 80, 30)
GUICtrlSetTip(-1,"Click here to add a value")
$cDel = GUICtrlCreateButton("Delete", 110, 145, 80, 30)
GUICtrlSetTip(-1,"Click here to delete a value")
$cMod = GUICtrlCreateButton("Modify", 210, 145, 80, 30)
GUICtrlSetTip(-1,"Click here to modify a value")
$cCan = GUICtrlCreateButton("Cancel", 310,145,80,30)
$cFind = GUICtrlCreateIcon("shell32.dll", -172, 480, 8, 16, 16)
GUICtrlSetTip(-1,"Clicca per cercare")
$cMore = GUICtrlCreateButton("See More...", 410,145,80,30)


GUICtrlSetState($cCan,$GUI_DISABLE)
GUISetState()

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit

;~ Come Visualizzare più informazioni
Case $cMore
$Fetch=GUICtrlRead(GUICtrlRead($cListView))
If $Fetch = "||" Then
MsgBox(16,"Errore","Selezionare prima una voce")
Else
$a = GUICreate("test2",200,200)
$1 = GUICtrlCreateInput("",10,10,70,20)
$2 = GUICtrlCreateInput("",10,70,70,20)
$3 = GUICtrlCreateInput("",100,10,70,20)
$4 = GUICtrlCreateInput("",100,70,70,20)
$5 = GUICtrlCreateInput("",150,10,70,20)
$aSplit = StringSplit($Fetch, "|")
GUICtrlSetData($1, $aSplit[1])
GUICtrlSetData($2, $aSplit[2])
GUICtrlSetData($3, $aSplit[3])
GUICtrlSetData($4, IniRead($sIni,$aSplit[1],"question","Not Set"))
GUICtrlSetData($5, IniRead($sIni,$aSplit[1],"answer","Not Set"))
GUISetState()
while 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
GUIDelete($a)
ExitLoop
EndSwitch
WEnd
EndIf
;~ Fine dei giochi :D

Case $cDel
$Fetch=GUICtrlRead(GUICtrlRead($cListView))
If $Fetch = "||" Then
MsgBox(16,"Errore","Selezionare prima una voce")
Else
; Read selected item
$sItemText = GUICtrlRead(GUICtrlRead($cListView))
; Split into the different columns
$aSplit = StringSplit($sItemText, "|")
; Delete the ini section
IniDelete($sIni, $aSplit[1])
; Reload the ListView
_Load_Ini()
EndIf
Case $GUI_EVENT_CLOSE
Exit

Case $cFind
find()

Case $cMod
$Fetch=GUICtrlRead(GUICtrlRead($cListView))
If $Fetch = "||" Then
MsgBox(16,"Errore","Selezionare prima una voce")
Else
Guictrlsetstate($cCan,$GUI_ENABLE)
; Read selected item
$sItemText = GUICtrlRead(GUICtrlRead($cListView))
If Not StringInStr($sItemText, "|") Then ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
ContinueLoop
EndIf

; Split into the different columns
$aSplit = StringSplit($sItemText, "|")

; Place items in inputs
GUICtrlSetData($cApp, $aSplit[1])
GUICtrlSetData($cUser, $aSplit[2])
GUICtrlSetData($cPwd, $aSplit[3])
; Change button name
GUICtrlSetData($cMod, "Save")
; Now wait for the "Save" button
GUICtrlSetTip($cMod,"Click here to save the value")
While 1
Switch GUIGetMsg()
Case $cCan
GUICtrlSetTip($cMod,"Click here to edit a value")
GUICtrlSetState($cCan,$GUI_DISABLE)
GUICtrlSetData($cMod, "Modify")
For $i = $cApp To $cPwd
GUICtrlSetData($i, "")
Next
ExitLoop
Case $cMod
GUICtrlSetTip($cMod,"Click here to edit a value")
GUICtrlSetState($cCan,$GUI_DISABLE)
; First delete the existing section
IniDelete($sIni, $aSplit[1])
; Rename the button again
GUICtrlSetData($cMod, "Modify")
; And now add the new data
; Check we have something to add
$sData = GUICtrlRead($cApp) & "|" & GUICtrlRead($cUser) & "|" & GUICtrlRead($cPwd)
If $sData <> "||" Then
; Add to the ini
IniWrite($sIni, GUICtrlRead($cApp), "name", GUICtrlRead($cUser))
IniWrite($sIni, GUICtrlRead($cApp), "pswd", GUICtrlRead($cPwd))
; Rewrite the ListView
_Load_Ini()
; Clear the inputs
For $i = $cApp To $cPwd
GUICtrlSetData($i, "")
Next
EndIf
; And continue
ExitLoop
EndSwitch
WEnd
EndIf


Case $cAdd
$lol = GUICtrlRead($cApp) And GUICtrlRead($cUser) And GUICtrlRead($cPwd)
If $lol = "" Then
MsgBox(16,"Tutti i campi sono vuoti","Scrivere almeno un campo")
Else
$bho = GUICtrlRead($cApp & " (" & $k & ")")
$sData = GUICtrlRead($cApp)
$aSections = IniReadSectionNames($sIni)
For $i = 1 To $aSections[0]
If $sData = $aSections[$i] Then
$cMsg = MsgBox(52, "Attenzione!", GUICtrlRead($cApp) & ' esiste già, aggiungerlo come"' & GUICtrlRead($cApp) & " (" & $k & ')"?')
If $cMsg = 1 Then
IniWrite($sIni, $bho, "name", GUICtrlRead($cUser))
IniWrite($sIni, $bho, "pswd", GUICtrlRead($cPwd))
_Load_Ini()
$k = $k + 01
IniWrite("config", "config", "k", $k)
ExitLoop ;<<<<<<<<<<<<<< All done here we can skip the loop (Nessie added this)
Else
GUISetState()
ExitLoop ;<<<<<<<<<<<<<<< Here is the problem! (and this)
EndIf
Else
$sData = GUICtrlRead($cApp) & "|" & GUICtrlRead($cUser) & "|" & GUICtrlRead($cPwd)
If $sData <> "||" Then
IniWrite($sIni, GUICtrlRead($cApp), "name", GUICtrlRead($cUser))
IniWrite($sIni, GUICtrlRead($cApp), "pswd", GUICtrlRead($cPwd))
_Load_Ini()
For $i = $cApp To $cPwd
GUICtrlSetData($i, "")
Next
EndIf
EndIf
Next
EndIf
EndSwitch
WEnd

Func _Load_Ini()
; Delete current contents
_GUICtrlListView_DeleteAllItems($cListView)
; Read sections
$aSections = IniReadSectionNames($sIni)
; Loop through sections
For $i = 1 To $aSections[0]
; Add app name to ListView data
$sData = $aSections[$i]
; Now add relevant sections
$sData &= "|" & IniRead($sIni, $aSections[$i], "name", "Not set")
$sData &= "|" & IniRead($sIni, $aSections[$i], "pswd", "Not set")
; And add data to ListView
GUICtrlCreateListViewItem($sData, $cListView)
Next
EndFunc

Func find()
$fText = _GUICtrlListView_FindText($cListView,GUICtrlRead($cSearch))
_GUICtrlListView_SetItemSelected($cListView, $fText, True, True)
_GUICtrlListView_ClickItem($cListView, $fText)
EndFunc
  • Moderators
Posted

Doctorkirk,

So what does not work in that script? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

Doctorkirk,

This will work as you wanted - see if you can work out why it does and yours did not: ;)

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
;#include

Global $sIni = "Test.ini", $k = Number(IniRead("config.ini", "config", "k", "1")) ; Set the default value to 0

;~ Spazio per la GUI di Login;

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xC4C4C4)

$cListView = GUICtrlCreateListView("App|Username|Password", 10, 190, 480, 300, Default, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetColumnWidth($cListView, 0, 155)
_GUICtrlListView_SetColumnWidth($cListView, 1, 155)
_GUICtrlListView_SetColumnWidth($cListView, 2, 155)

_Load_Ini()
GUICtrlCreateLabel("App:", 15, 69, 100, 20)
GUICtrlCreateLabel("Username:", 184, 69, 100, 20)
GUICtrlCreateLabel("Password:", 350, 69, 100, 20)
GUICtrlCreateLabel("Search:", 325, 8, 36, 20)

$cSearch = GUICtrlCreateInput("", 365, 5, 110, 20)
GUICtrlSetTip(-1, "Scrivi nome App che vuoi cercare")
$cApp = GUICtrlCreateInput("", 14, 85, 130, 20)
$cUser = GUICtrlCreateInput("", 183, 85, 130, 20)
$cPwd = GUICtrlCreateInput("", 349, 85, 130, 20)

;~ $bFetch = GUICtrlCreateButton("Vis.", 10, 310, 80, 30)
$cAdd = GUICtrlCreateButton("Add", 10, 145, 80, 30)
GUICtrlSetTip(-1, "Click here to add a value")
$cDel = GUICtrlCreateButton("Delete", 110, 145, 80, 30)
GUICtrlSetTip(-1, "Click here to delete a value")
$cMod = GUICtrlCreateButton("Modify", 210, 145, 80, 30)
GUICtrlSetTip(-1, "Click here to modify a value")
$cCan = GUICtrlCreateButton("Cancel", 310, 145, 80, 30)
$cFind = GUICtrlCreateIcon("shell32.dll", -172, 480, 8, 16, 16)
GUICtrlSetTip(-1, "Clicca per cercare")
$cMore = GUICtrlCreateButton("See More...", 410, 145, 80, 30)


GUICtrlSetState($cCan, $GUI_DISABLE)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

;~ Come Visualizzare più informazioni
        Case $cMore
            $Fetch = GUICtrlRead(GUICtrlRead($cListView))
            If $Fetch = "||" Then
                MsgBox(16, "Errore", "Selezionare prima una voce")
            Else
                $a = GUICreate("test2", 200, 200)
                $1 = GUICtrlCreateInput("", 10, 10, 70, 20)
                $2 = GUICtrlCreateInput("", 10, 70, 70, 20)
                $3 = GUICtrlCreateInput("", 100, 10, 70, 20)
                $4 = GUICtrlCreateInput("", 100, 70, 70, 20)
                $5 = GUICtrlCreateInput("", 150, 10, 70, 20)
                $aSplit = StringSplit($Fetch, "|")
                GUICtrlSetData($1, $aSplit[1])
                GUICtrlSetData($2, $aSplit[2])
                GUICtrlSetData($3, $aSplit[3])
                GUICtrlSetData($4, IniRead($sIni, $aSplit[1], "question", "Not Set"))
                GUICtrlSetData($5, IniRead($sIni, $aSplit[1], "answer", "Not Set"))
                GUISetState()
                While 1
                    Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                            GUIDelete($a)
                            ExitLoop
                    EndSwitch
                WEnd
            EndIf
;~ Fine dei giochi :D

        Case $cDel
            $Fetch = GUICtrlRead(GUICtrlRead($cListView))
            If $Fetch = "||" Then
                MsgBox(16, "Errore", "Selezionare prima una voce")
            Else
                ; Read selected item
                $sItemText = GUICtrlRead(GUICtrlRead($cListView))
                ; Split into the different columns
                $aSplit = StringSplit($sItemText, "|")
                ; Delete the ini section
                IniDelete($sIni, $aSplit[1])
                ; Reload the ListView
                _Load_Ini()
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit

        Case $cFind
            find()

        Case $cMod
            $Fetch = GUICtrlRead(GUICtrlRead($cListView))
            If $Fetch = "||" Then
                MsgBox(16, "Errore", "Selezionare prima una voce")
            Else
                GUICtrlSetState($cCan, $GUI_ENABLE)
                ; Read selected item
                $sItemText = GUICtrlRead(GUICtrlRead($cListView))
                If Not StringInStr($sItemText, "|") Then ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    ContinueLoop
                EndIf

                ; Split into the different columns
                $aSplit = StringSplit($sItemText, "|")

                ; Place items in inputs
                GUICtrlSetData($cApp, $aSplit[1])
                GUICtrlSetData($cUser, $aSplit[2])
                GUICtrlSetData($cPwd, $aSplit[3])
                ; Change button name
                GUICtrlSetData($cMod, "Save")
                ; Now wait for the "Save" button
                GUICtrlSetTip($cMod, "Click here to save the value")
                While 1
                    Switch GUIGetMsg()
                        Case $cCan
                            GUICtrlSetTip($cMod, "Click here to edit a value")
                            GUICtrlSetState($cCan, $GUI_DISABLE)
                            GUICtrlSetData($cMod, "Modify")
                            For $i = $cApp To $cPwd
                                GUICtrlSetData($i, "")
                            Next
                            ExitLoop
                        Case $cMod
                            GUICtrlSetTip($cMod, "Click here to edit a value")
                            GUICtrlSetState($cCan, $GUI_DISABLE)
                            ; First delete the existing section
                            IniDelete($sIni, $aSplit[1])
                            ; Rename the button again
                            GUICtrlSetData($cMod, "Modify")
                            ; And now add the new data
                            ; Check we have something to add
                            $sData = GUICtrlRead($cApp) & "|" & GUICtrlRead($cUser) & "|" & GUICtrlRead($cPwd)
                            If $sData <> "||" Then
                                ; Add to the ini
                                IniWrite($sIni, GUICtrlRead($cApp), "name", GUICtrlRead($cUser))
                                IniWrite($sIni, GUICtrlRead($cApp), "pswd", GUICtrlRead($cPwd))
                                ; Rewrite the ListView
                                _Load_Ini()
                                ; Clear the inputs
                                For $i = $cApp To $cPwd
                                    GUICtrlSetData($i, "")
                                Next
                            EndIf
                            ; And continue
                            ExitLoop
                    EndSwitch
                WEnd
            EndIf


        Case $cAdd
            $lol = GUICtrlRead($cApp) And GUICtrlRead($cUser) And GUICtrlRead($cPwd)
            If $lol = "" Then
                MsgBox(16, "Tutti i campi sono vuoti", "Scrivere almeno un campo")
            Else
                $bho = GUICtrlRead($cApp) & "(" & $k & ")"
                $sData = GUICtrlRead($cApp)
                $aSections = IniReadSectionNames($sIni)
                ; Check if app name already exists
                For $i = 1 To $aSections[0]
                    If $sData = $aSections[$i] Then
                        ExitLoop
                    EndIf
                Next
                ; Did it?
                If $i > $aSections[0] Then
                    ; It did not exist so save
                    $sData = GUICtrlRead($cApp) & "|" & GUICtrlRead($cUser) & "|" & GUICtrlRead($cPwd)
                    If $sData <> "||" Then
                        IniWrite($sIni, GUICtrlRead($cApp), "name", GUICtrlRead($cUser))
                        IniWrite($sIni, GUICtrlRead($cApp), "pswd", GUICtrlRead($cPwd))
                    EndIf
                Else
                    ; It did exist so ask if it is to replace
                    $cMsg = MsgBox(4 + 48, "Attenzione!", GUICtrlRead($cApp) & ' already exists, do you want to overwrite the existing data?')
                    ; MsgBox has Yes/No buttons so will return 6 or 7
                    If $cMsg = 6 Then
                        ; Overwrite
                        IniWrite($sIni, GUICtrlRead($cApp), "name", GUICtrlRead($cUser))
                        IniWrite($sIni, GUICtrlRead($cApp), "pswd", GUICtrlRead($cPwd))
                    Else
                        ; Create new dataset
                        IniWrite($sIni, $bho, "name", GUICtrlRead($cUser))
                        IniWrite($sIni, $bho, "pswd", GUICtrlRead($cPwd))
                        ; Increase numeric count
                        $k += 01
                        IniWrite("config", "config", "k", $k)
                    EndIf
                EndIf
                ; Reload ListView
                _Load_Ini()
                ; Clear inputs
                For $i = $cApp To $cPwd
                    GUICtrlSetData($i, "")
                Next
            EndIf
    EndSwitch
WEnd

Func _Load_Ini()
    ; Delete current contents
    _GUICtrlListView_DeleteAllItems($cListView)
    ; Read sections
    $aSections = IniReadSectionNames($sIni)
    ; Loop through sections
    For $i = 1 To $aSections[0]
        ; Add app name to ListView data
        $sData = $aSections[$i]
        ; Now add relevant sections
        $sData &= "|" & IniRead($sIni, $aSections[$i], "name", "Not set")
        $sData &= "|" & IniRead($sIni, $aSections[$i], "pswd", "Not set")
        ; And add data to ListView
        GUICtrlCreateListViewItem($sData, $cListView)
    Next
EndFunc   ;==>_Load_Ini

Func find()
    $fText = _GUICtrlListView_FindText($cListView, GUICtrlRead($cSearch))
    _GUICtrlListView_SetItemSelected($cListView, $fText, True, True)
    _GUICtrlListView_ClickItem($cListView, $fText)
EndFunc   ;==>find

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

ok, found a bad bug, if i add Facebook twice, so i reach the Facebook (2) record, if i try to add a second twitter voice it saves it like Twitter (3).

I adopted your script, and i have a question now, or better 2, first, i don't know how but i can't search anymore if not for section names (and now they're 001/002 ecc..), and i did not understood this:

$sSection = StringFormat("%03i", $i)
could you exsplain what is this? :)
  • Moderators
Posted

Doctorkirk,

That is not a bug, it is implicit on the way you implemented the incremental title number in the code you wrote. This was one reason I did not like your implementation, so I am glad you decided to use my solution. ;)

The title of the app is now within the ini under the "app" key - so you will have to get an array of those values to search. I would suggest a 2D array (SectionName & app value) so that you can search for the app name and then automatically get the section name as well.

StringFormat is quite a complicated function which needs a bit of practise to master. In this case the "format comtrol" reads:

Symbol  Parameter  Meaning
%           I am a format control string
0     flag       Lead with zeros
2     width       Make the return at least this long
     precision This is optional and we do not need it here
i     type       Integer

The "Parameter" words will help you find the correct section of the Help file page to read for more information. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

The "Parameter" words will help you find the correct section of the Help file page to read for more information. ;)

Ok, thanks understood! :)

I would suggest a 2D array

Ehm... i do not even know the existance of 2D Array, and so, i do not even know hot to use it :/

  • Moderators
Posted

Doctorkirk,

Wiki Array tutorial. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Ok, read the Wiki, but as i was expecting, i understand quite anything xD i tried to find a way myself, i think i quite reach the goal but i feel i'm missing something... :/

Func find()
$IRSN = IniReadSectionNames($sIni)
For $i = 1 To $IRSN[0]
$IRS = IniReadSection($sIni,$IRSN[$i])
For $o = 1 To $IRS[0]
$IR = IniRead($sIni,$IRSN[$i],$IRS[$o],"Not Set")
$GcR = GUICtrlRead($sSearch)
If $GcR = $IR Then
$fText = _GUICtrlListView_FindText($cListView,GUICtrlRead($sSearch))
_GUICtrlListView_SetItemSelected($cListView, $fText, True, True)
_GUICtrlListView_ClickItem($cListView, $fText)
Else
EndIf
Next
ExitLoop
Next
EndFunc ;==> Find
  • Moderators
Posted

Doctorkirk,

In looking at the problem again I see you can do it without using an array: :)

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <Array.au3>

Global $sIni = "Test.ini"

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xC4C4C4)

$cListView = GUICtrlCreateListView("Section|App|Username|Password", 10, 190, 480, 300, Default, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetColumnWidth($cListView, 0, 0)
_GUICtrlListView_SetColumnWidth($cListView, 1, 155)
_GUICtrlListView_SetColumnWidth($cListView, 2, 155)
_GUICtrlListView_SetColumnWidth($cListView, 3, 155)

_Load_Ini()
GUICtrlCreateLabel("App:", 15, 69, 100, 20)
GUICtrlCreateLabel("Username:", 184, 69, 100, 20)
GUICtrlCreateLabel("Password:", 350, 69, 100, 20)
GUICtrlCreateLabel("Search:", 325, 8, 36, 20)

$cSearch = GUICtrlCreateInput("", 365, 5, 110, 20)
GUICtrlSetTip(-1, "Scrivi nome App che vuoi cercare")
$cApp = GUICtrlCreateInput("", 14, 85, 130, 20)
$cUser = GUICtrlCreateInput("", 183, 85, 130, 20)
$cPwd = GUICtrlCreateInput("", 349, 85, 130, 20)

;~ $bFetch = GUICtrlCreateButton("Vis.", 10, 310, 80, 30)
$cAdd = GUICtrlCreateButton("Add", 10, 145, 80, 30)
GUICtrlSetTip(-1, "Click here to add a value")
$cDel = GUICtrlCreateButton("Delete", 110, 145, 80, 30)
GUICtrlSetTip(-1, "Click here to delete a value")
$cMod = GUICtrlCreateButton("Modify", 210, 145, 80, 30)
GUICtrlSetTip(-1, "Click here to modify a value")
$cCan = GUICtrlCreateButton("Cancel", 310, 145, 80, 30)
$cFind = GUICtrlCreateIcon("shell32.dll", -172, 480, 8, 16, 16)
GUICtrlSetTip(-1, "Clicca per cercare")
$cMore = GUICtrlCreateButton("See More...", 410, 145, 80, 30)


GUICtrlSetState($cCan, $GUI_DISABLE)
GUISetState()

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cDel
            ; Read selected item
            $sItemText = GUICtrlRead(GUICtrlRead($cListView))
            ; Split into the different columns
            $aSplit = StringSplit($sItemText, "|")
            ; Delete the ini section
            IniDelete($sIni, $aSplit[1])
            ; Reload the ListView
            _Load_Ini()
        Case $cMod
            ; Read selected item
            $sItemText = GUICtrlRead(GUICtrlRead($cListView))
            ; Split into the different columns
            $aSplit = StringSplit($sItemText, "|")
            ; Place items in inputs
            GUICtrlSetData($cApp, $aSplit[2])
            GUICtrlSetData($cUser, $aSplit[3])
            GUICtrlSetData($cPwd, $aSplit[4])
            ; Change button name
            GUICtrlSetData($cMod, "Save")
            ; Now wait for the "Save" button
            While 1
                Switch GUIGetMsg()
                    Case $cMod
                        ; First delete the existing section
                        IniDelete($sIni, $aSplit[1])
                        ; Rename the button again
                        GUICtrlSetData($cMod, "Modify")
                        ; And now add the new data
                        ; Check we have something to add
                        $sData = GUICtrlRead($cApp) & "|" & GUICtrlRead($cUser) & "|" & GUICtrlRead($cPwd)
                        If $sData <> "||" Then
                            ; Add to the ini
                            IniWrite($sIni, $aSplit[1], "app", GUICtrlRead($cApp))
                            IniWrite($sIni, $aSplit[1], "name", GUICtrlRead($cUser))
                            IniWrite($sIni, $aSplit[1], "pswd", GUICtrlRead($cPwd))
                            ; Rewrite the ListView
                            _Load_Ini()
                            ; Clear the inputs
                            For $i = $cApp To $cPwd
                                GUICtrlSetData($i, "")
                            Next
                        EndIf
                        ; And continue
                        ExitLoop
                EndSwitch
            WEnd
        Case $cAdd
            ; Check we have something to add
            $sData = GUICtrlRead($cApp) & "|" & GUICtrlRead($cUser) & "|" & GUICtrlRead($cPwd)
            If $sData <> "||" Then
                ; Find the next available section
                $aSectionNames = IniReadSectionNames($sIni)
                ; Get into order
                _ArraySort($aSectionNames, 0, 1)
                ; Now look to see if there are any holes in the list
                For $i = 1 To $aSectionNames[0]
                    If Number($aSectionNames[$i]) <> $i Then
                        ; There is a hole - so fill it
                        ExitLoop
                    EndIf
                Next
                ; Either we found a hole or we need to add to the end of the list
                $sSection = StringFormat("%03i", $i)
                ; Add to the ini
                IniWrite($sIni, $sSection, "app", GUICtrlRead($cApp))
                IniWrite($sIni, $sSection, "name", GUICtrlRead($cUser))
                IniWrite($sIni, $sSection, "pswd", GUICtrlRead($cPwd))
                ; Rewrite the ListView
                _Load_Ini()
                ; Clear the inputs
                For $i = $cApp To $cPwd
                    GUICtrlSetData($i, "")
                Next
            EndIf
        Case $cFind ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $sSearchText = GUICtrlRead($cSearch)
            If $sSearchText <> "" Then
                For $i = 0 To _GUICtrlListView_GetItemCount($cListView)
                    $sItemText = _GUICtrlListView_GetItemTextString($cListView, $i)
                    If StringInStr($sItemText, $sSearchText) Then
                        _GUICtrlListView_ClickItem($cListView, $i)
                        ExitLoop
                    EndIf
                Next
                GUICtrlSetData($cSearch, "")
            EndIf
    EndSwitch

WEnd

Func _Load_Ini()
    ; Delete current contents
    _GUICtrlListView_DeleteAllItems($cListView)
    ; Read sections
    Local $aSections = IniReadSectionNames($sIni)
    ; Loop through sections
    For $i = 1 To $aSections[0]
        $sData = $aSections[$i]
        ; Add relevant sections to ListView data
        $sData &= "|" & IniRead($sIni, $aSections[$i], "app", "Not set")
        $sData &= "|" & IniRead($sIni, $aSections[$i], "name", "Not set")
        $sData &= "|" & IniRead($sIni, $aSections[$i], "pswd", "Not set")
        ; And add data to ListView
        GUICtrlCreateListViewItem($sData, $cListView)
    Next
EndFunc

Func _Search_LV($sText)

EndFunc

But arrays are an essential part of a coder's toolbox, so the time you spent studying then was not wasted. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...