Jump to content

Help with saving configurations in a GUI


Recommended Posts

Hi everyone. I am new to this forum, and lately I am picking up autoit3.
I am trying to develop something for my family, they need it. It is for their personal data, passports and what not.
So I know a little bit, like basics, but  I looked up on google and got this list. My problem with this list is, how can I make it so after exiting the program, the list saves your added items? And, how can I add a delete button to erase an item.
Below is the script: It is not mine and credits goes to who made it.
 #include <GUIConstantsEx.au3>
 #include <GuiListView.au3>

 Opt("GUIOnEventMode", 1)

MainGUI()

 ; ----- GUIs
Func MainGUI()
  Global $listview
  $listGUI = GUICreate("AutoIt list item GUI", 400, 200, 100, 200, -1)
  GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Main")
  $listview = GUICtrlCreateListView("Users", 10, 10, 200, 150)
  _GUICtrlListView_SetColumnWidth($listview, 0, 150)

  GUICtrlCreateListViewItem("First Item", $listview)
  GUICtrlCreateListViewItem("Second Item", $listview)
  GUICtrlCreateListViewItem("Third Item", $listview)

  $BtnAdd = GUICtrlCreateButton("Add Item", 10, 165, 80, 30)
  GUICtrlSetOnEvent(-1, "Addi")
  $BtnSelect = GUICtrlCreateButton("Select", 100, 165, 80, 30)
  GUICtrlSetOnEvent(-1, "SelectItem")

  GUISetState()
 
  While 1
    Sleep(10)
  WEnd
EndFunc
 ; ///// Functions
Func Addi()
   $sToAdd = InputBox("Add", "Enter Item Name", "")
   GUICtrlCreateListViewItem($sToAdd, $listview)
EndFunc

Func SelectItem()
  $sItem = GUICtrlRead(GUICtrlRead($listview))
  $sItem = StringTrimRight($sItem, 1) ; Will remove the pipe "|" from the end of the string
  MsgBox(0, "Selected Item", $sItem)
EndFunc
 
Func On_Close_Main()
   Exit
EndFunc

Link to comment
Share on other sites

Hi @Sajadaliraqi, and welcome to the AutoIt forums :welcome:
You can use a flat file, or a SQLite DB to save your data permantly, and, to design a GUI, try to use Koda, which is in the Program Files (x86)\SciTE\Koda directory; from there, just use _GUICtrlListView_DeleteItem() to delete a specific item.
Use the code <> tag when you post the code, so it doesn't mess up! :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

koda you find  in autoit  , openscite   -- tools  koda fromdesign  or Alt+m

i suggest pin in taskbar  

also you find here C:\Program Files (x86)\AutoIt3\SciTE\Koda

 

Edited by faustf
Link to comment
Share on other sites

i do somthing , not  save because  you must do also somthing , look in help file is your firend , but  best friend is  google , autoi + inifilesave , for start

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

Opt("GUIOnEventMode", 1)

Global $listview, $listview

MainGUI()

; ----- GUIs
Func MainGUI()

    $listGUI = GUICreate("AutoIt list item GUI", 400, 200, 100, 200, -1)
    $listview = GUICtrlCreateListView("Users", 10, 10, 200, 150)
    _GUICtrlListView_SetColumnWidth($listview, 0, 150)
    GUICtrlCreateListViewItem("First Item", $listview)
    GUICtrlCreateListViewItem("Second Item", $listview)
    GUICtrlCreateListViewItem("Third Item", $listview)
    $BtnAdd = GUICtrlCreateButton("Add Item", 10, 165, 80, 30)
    $BtnSelect = GUICtrlCreateButton("Select", 100, 165, 80, 30)
    GUISetState()

    GUISetOnEvent($GUI_EVENT_CLOSE, On_Close_Main)
    GUICtrlSetOnEvent($BtnSelect, SelectItem)
    GUICtrlSetOnEvent($BtnAdd, Addi)

EndFunc   ;==>MainGUI

Func _SaveinFile()

    Local $SelectedItemIndex = -1
    Local $GetCount = _GUICtrlListView_GetItemCount($listview)

    For $i = 0 To  $GetCount - 1
        $LineInfo = _GUICtrlListView_GetItemText($listview, $i)
        MsgBox(0, 'Info', $LineInfo)
    Next
EndFunc   ;==>_SaveinFile



; ///// Functions
Func Addi()
    $sToAdd = InputBox("Add", "Enter Item Name", "")
    GUICtrlCreateListViewItem($sToAdd, $listview)
EndFunc   ;==>Addi

Func SelectItem()
    $sItem = GUICtrlRead(GUICtrlRead($listview))
    $sItem = StringTrimRight($sItem, 1) ; Will remove the pipe "|" from the end of the string
    MsgBox(0, "Selected Item", $sItem)
EndFunc   ;==>SelectItem

Func On_Close_Main()
    _SaveinFile()
    Exit
EndFunc   ;==>On_Close_Main

While 1
    Sleep(10)
WEnd

i suggest read also a wiki of autoit 

some example  you must correct for my advise

when you generate a variable  use suffi  $aCiao  a = array , $sCiao s= string

i also prefer insert  if is Local or Global  $aLCiao or $sGCiao   when you write long script you can recognize much better

look the script   while1    , global variable where is , and much more

i hope was helpfull

Link to comment
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
 Share

  • Recently Browsing   0 members

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