Jump to content

Saving and loading info


Recommended Posts

Hihi coders.

I really need help. Im making one presales program. I can handle my script well, but only thing i cant uderstand. How to save all entrys and load them later.

I know how to do with 1 entry only but i have like 100 entrys coming up to there.

There are no buttons atm for saving and loading, but i will make those

#include <GUIConstantsEx.au3>

; Here is the array
Global $aArray[15] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"]
Global $aArray1[2] = ["N", "M"]
; And here we get the elements into a list
$sList = ""
For $i = 0 To UBound($aArray) - 1
    $sList &= "|" & $aArray[$i]
Next

$sList1 = ""
For $i = 0 To UBound($aArray1) - 1
    $sList1 &= "|" & $aArray1[$i]
Next
; Create a GUI
#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$Hind = GUICtrlCreateLabel( "Ühiku Hind M", 10, 420)
Global $Hindm = GUICtrlCreateInput("2.40", 15, 440, 50, 20)
$Hind1 = GUICtrlCreateLabel( "Ühiku Hind N", 100, 420)
Global $Hindn = GUICtrlCreateInput("2.40", 105, 440, 50, 20)

$Tellija = GUICtrlCreateLabel( "TELLIJA NIMI", 20, 15, 125)
GUICtrlSetFont($Tellija, 14)
Global $Nimi = GUICtrlCreateInput("", 10, 40, 150, 20)
Global $Nimi1 = GUICtrlCreateInput("", 10, 70, 150, 20)
Global $Nimi2 = GUICtrlCreateInput("", 10, 100, 150, 20)
Global $Nimi3 = GUICtrlCreateInput("", 10, 130, 150, 20)
Global $Nimi4 = GUICtrlCreateInput("", 10, 160, 150, 20)
Global $Nimi5 = GUICtrlCreateInput("", 10, 190, 150, 20)
Global $Nimi6 = GUICtrlCreateInput("", 10, 220, 150, 20)
Global $Nimi7 = GUICtrlCreateInput("", 10, 250, 150, 20)
Global $Nimi8 = GUICtrlCreateInput("", 10, 280, 150, 20)
Global $Nimi9 = GUICtrlCreateInput("", 10, 310, 150, 20)


$Kogus = GUICtrlCreateLabel( "KOGUS", 195, 15, 125)
GUICtrlSetFont($Kogus, 14)
; Create the combo
$hCombo = GUICtrlCreateCombo("", 200, 40, 50, 20)
$hCombo1 = GUICtrlCreateCombo("", 200, 70, 50, 20)
$hCombo2 = GUICtrlCreateCombo("", 200, 100, 50, 20)
$hCombo3 = GUICtrlCreateCombo("", 200, 130, 50, 20)
$hCombo4 = GUICtrlCreateCombo("", 200, 160, 50, 20)
$hCombo5 = GUICtrlCreateCombo("", 200, 190, 50, 20)
$hCombo6 = GUICtrlCreateCombo("", 200, 220, 50, 20)
$hCombo7 = GUICtrlCreateCombo("", 200, 250, 50, 20)
$hCombo8 = GUICtrlCreateCombo("", 200, 280, 50, 20)
$hCombo9 = GUICtrlCreateCombo("", 200, 310, 50, 20)
; And fill it

GUICtrlSetData($hCombo, $sList)
GUICtrlSetData($hCombo1, $sList)
GUICtrlSetData($hCombo2, $sList)
GUICtrlSetData($hCombo3, $sList)
GUICtrlSetData($hCombo4, $sList)
GUICtrlSetData($hCombo5, $sList)
GUICtrlSetData($hCombo6, $sList)
GUICtrlSetData($hCombo7, $sList)
GUICtrlSetData($hCombo8, $sList)
GUICtrlSetData($hCombo9, $sList)


$NM = GUICtrlCreateLabel( "N või M", 280, 15, 125)
GUICtrlSetFont($NM, 14)
; Create the combo
$hComboa = GUICtrlCreateCombo("", 280, 40, 50, 20)
$hCombob = GUICtrlCreateCombo("", 280, 70, 50, 20)
$hComboc = GUICtrlCreateCombo("", 280, 100, 50, 20)
$hCombod = GUICtrlCreateCombo("", 280, 130, 50, 20)
$hComboe = GUICtrlCreateCombo("", 280, 160, 50, 20)
$hCombof = GUICtrlCreateCombo("", 280, 190, 50, 20)
$hCombog = GUICtrlCreateCombo("", 280, 220, 50, 20)
$hComboh = GUICtrlCreateCombo("", 280, 250, 50, 20)
$hComboi = GUICtrlCreateCombo("", 280, 280, 50, 20)
$hComboj = GUICtrlCreateCombo("", 280, 310, 50, 20)

GUICtrlSetData($hComboa, $sList1)
GUICtrlSetData($hCombob, $sList1)
GUICtrlSetData($hComboc, $sList1)
GUICtrlSetData($hCombod, $sList1)
GUICtrlSetData($hComboe, $sList1)
GUICtrlSetData($hCombof, $sList1)
GUICtrlSetData($hCombog, $sList1)
GUICtrlSetData($hComboh, $sList1)
GUICtrlSetData($hComboi, $sList1)
GUICtrlSetData($hComboj, $sList1)


GUISetState()




While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd










Func _TERMINATE()
Exit
EndFunc   ;==>Terminate

 

Link to comment
Share on other sites

What is you want to save and load ? The input fields ? The combos ?  And when you want to save, do you mean save and before you quit the GUI ? Or just saving the data as a log purpose ?

Link to comment
Share on other sites

14 minutes ago, Nine said:

What is you want to save and load ? The input fields ? The combos ?  And when you want to save, do you mean save and before you quit the GUI ? Or just saving the data as a log purpose ?

umm lets say i fill all the info, fields, combos etc. and then i press save button. and i can quit program and whenever i need i can load saved data for future use

Link to comment
Share on other sites

Ok, I would probably use .ini file to save and retrieve infos.  Look into help file for IniWriteSection and IniReadSection.  You may also consider using arrays in your GUI instead of single vars like you do now.  It would facilitate the transfer to file.

Link to comment
Share on other sites

Here is how I would do it:

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

Global $g_sFileName = @ScriptDir & "\Example.ini"
; Here is the array
Global $g_aCombo1[15] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"]
Global $g_aComboA[2] = ["N", "M"]
; And here we get the elements into a list
Global $g_sCombo1 = _ArrayToString($g_aCombo1)
    If @error Then Exit MsgBox(4096, "List Array Error", __ArrayToStringError(@error, "$g_sCombo1"))
Global $g_sComboA = _ArrayToString($g_aComboA)
    If @error Then Exit MsgBox(4096, "List1 Array Error", __ArrayToStringError(@error), "$g_sComboA")

Global $g_aIdNim[10], $g_aIdComboN[10], $g_aIdComboA[10]
Global $iTop = 40

Global $g_hGUI = GUICreate("Test", 500, 500)

GUICtrlCreateLabel( "Ühiku Hind M", 10, 420)
Global $g_idHindm = GUICtrlCreateInput("2.40", 15, 440, 50, 20)
    GUICtrlSetData($g_idHindm, IniRead($g_sFileName, "General", "Hindm", GUICtrlRead($g_idHindm)))

GUICtrlCreateLabel( "Ühiku Hind N", 100, 420)
Global $g_idHindn = GUICtrlCreateInput("2.40", 105, 440, 50, 20)
    GUICtrlSetData($g_idHindn, IniRead($g_sFileName, "General", "Hindn", GUICtrlRead($g_idHindn)))

GUICtrlCreateLabel( "TELLIJA NIMI", 20, 15, 125)
    GUICtrlSetFont(-1, 14)
GUICtrlCreateLabel( "KOGUS", 195, 15, 125)
    GUICtrlSetFont(-1, 14)
GUICtrlCreateLabel( "N või M", 280, 15, 125)
    GUICtrlSetFont(-1, 14)

For $i = 0 To UBound($g_aIdNim) - 1
    $g_aIdNim[$i] = GUICtrlCreateInput("", 10, $iTop, 150, 20)
        GUICtrlSetData($g_aIdNim[$i], IniRead($g_sFileName, "TELLIJA NIMI", $i, ""))
    ;~ Create ComboN (N = Numeric)
    $g_aIdComboN[$i] = GUICtrlCreateCombo("", 200, $iTop, 50, 20)
    ;~ Add Data, including last saved ComboN selection
        GUICtrlSetData($g_aIdComboN[$i], $g_sCombo1, IniRead($g_sFileName, "KOGUS", $i, ""))
    ;~ Create ComboA (A = Alpha)
    $g_aIdComboA[$i] = GUICtrlCreateCombo("", 280, $iTop, 50, 20)
    ;~ Add Data, including last saved ComboA selection
        GUICtrlSetData($g_aIdComboA[$i], $g_sComboA, IniRead($g_sFileName, "N või M", $i, ""))
    $iTop += 30
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
_SaveData()

Func _SaveData()
    IniWrite($g_sFileName, "General", $i, GUICtrlRead($g_idHindm))
    IniWrite($g_sFileName, "General", $i, GUICtrlRead($g_idHindn))
    For $i = 0 To UBound($g_aIdNim) - 1
        IniWrite($g_sFileName, "TELLIJA NIMI", $i, GUICtrlRead($g_aIdNim[$i]))
        IniWrite($g_sFileName, "KOGUS", $i, GUICtrlRead($g_aIdComboN[$i]))
        IniWrite($g_sFileName, "N või M", $i, GUICtrlRead($g_aIdComboA[$i]))
    Next
EndFunc

Func __ArrayToStringError($_iError = 0, $_sArray = "Array")
    Local $sArrayToStringError = $_sArray
    Switch $_iError
        Case 1
            $sArrayToStringError &= " is not an array"
        Case 2
            $sArrayToStringError &= "$g_aCombo1 is not a 1D or 2D array"
        Case 3
            $sArrayToStringError &= "$iStart_Row or $iEnd_Row outside array bounds"
        Case 4
            $sArrayToStringError &= "$iStart_Row greater then $iEnd_Row"
        Case 5
            $sArrayToStringError &= "$iStart_Col or $iEnd_Col outside array bounds"
        Case 6
            $sArrayToStringError &= "$iStart_Col greater then $iEnd_Col"
    EndSwitch
    Return
EndFunc

 

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...