Jump to content
Sign in to follow this  
Shark007

execute func as stored in ini

Recommended Posts

Shark007

my application has over 80 funtions. It works great.

I am trying to build a restore feature into it so that a user can easily restore to a previous saved state.

I'd like to be able to read a saved ini file which has the functions saved as GUIchecked = 1 , GUIunchecked = 4

and then have the restore function execute the functions that are set to 1 in the saved ini

ini example;

[Current]
ABC1=1
ABC2=4
ABC3=4
DEF1=4
DEF2=1
DEF3=4

$restore = IniReadSection(@AppDataCommonDir & '\restore.ini', 'Current')
For $i = 0 To (UBound($restore) - 1)
Call($restore[$i][0])
Next

your assistance would be appreciated.

Share this post


Link to post
Share on other sites
smashly

Hi, this example based on the Checkbox text is the same name as the function it calls.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $Ini = @ScriptDir & "\restore.ini"
Global $Sect = "Current"
Global $ChkBox[6] = ["ABC1", "ABC2", "ABC3", "DEF1", "DEF2", "DEF3"]

$hGui = GUICreate("", 400, 405)
For $i = 0 To UBound($ChkBox) - 1
    $ChkBox[$i] = GUICtrlCreateCheckbox($ChkBox[$i], 5, ($i * 20) + 5, 80, 15)
Next
GUISetState()

Load()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Save()
            Exit
        Case $ChkBox[0] To $ChkBox[UBound($ChkBox) - 1]
            Call(GUICtrlRead($Msg, 1))
    EndSwitch
WEnd

Func Save()
    For $i = 0 To UBound($ChkBox) - 1
        IniWrite($Ini, $Sect, GUICtrlRead($ChkBox[$i], 1), GUICtrlRead($ChkBox[$i]))
    Next
EndFunc   ;==>Save

Func Load()
    Local $aIRS
    If Not FileExists($Ini) Then Return
    $aIRS = IniReadSection($Ini, $Sect)
    If @error Then Return
    For $i = 1 To $aIRS[0][0]
        If IniRead($Ini, $Sect, $aIRS[$i][0], "") = 1 Then
            GUICtrlSetState($ChkBox[$i - 1], 1)
            Call($aIRS[$i][0])
        EndIf
    Next
EndFunc   ;==>Load

Func ABC1()
    Local $ChkState
    If GUICtrlRead($ChkBox[0]) = 1 Then
        $ChkState = "Checked"
    Else
        $ChkState = "UnChecked"
    EndIf
    ConsoleWrite("Executed ABC1 - Checkbox: " & $ChkState & @LF)
EndFunc   ;==>ABC1

Func ABC2()
    Local $ChkState
    If GUICtrlRead($ChkBox[1]) = 1 Then
        $ChkState = "Checked"
    Else
        $ChkState = "UnChecked"
    EndIf
    ConsoleWrite("Executed ABC2 - Checkbox: " & $ChkState & @LF)
EndFunc   ;==>ABC2

Func ABC3()
    Local $ChkState
    If GUICtrlRead($ChkBox[2]) = 1 Then
        $ChkState = "Checked"
    Else
        $ChkState = "UnChecked"
    EndIf
    ConsoleWrite("Executed ABC3 - Checkbox: " & $ChkState & @LF)
EndFunc   ;==>ABC3

Func DEF1()
    Local $ChkState
    If GUICtrlRead($ChkBox[3]) = 1 Then
        $ChkState = "Checked"
    Else
        $ChkState = "UnChecked"
    EndIf
    ConsoleWrite("Executed DEF1 - Checkbox: " & $ChkState & @LF)
EndFunc   ;==>DEF1

Func DEF2()
    Local $ChkState
    If GUICtrlRead($ChkBox[4]) = 1 Then
        $ChkState = "Checked"
    Else
        $ChkState = "UnChecked"
    EndIf
    ConsoleWrite("Executed DEF2 - Checkbox: " & $ChkState & @LF)
EndFunc   ;==>DEF2

Func DEF3()
    Local $ChkState
    If GUICtrlRead($ChkBox[5]) = 1 Then
        $ChkState = "Checked"
    Else
        $ChkState = "UnChecked"
    EndIf
    ConsoleWrite("Executed DEF3 - Checkbox: " & $ChkState & @LF)
EndFunc   ;==>DEF3

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites
Shark007

thanks smashly, you assistance is greatly appreciated.

I didnt think my 3 lines of code was going to suffice . . .

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  

×