Jump to content

Log system not displaying checked check boxes in GUI correctly


aa2zz6
 Share

Recommended Posts

I am trying to get my log system in the GUI to display the checked check boxes when I load them in from a ini file but I'm having an issue with it writing correctly. It seems to be writing duplicates when you have more than 1 checkbox selected.

Results - 

3:12:43 PMCheckbox 1 is checked
3:12:43 PMCheckbox 1 is checked
3:12:43 PMCheckbox 2 is checked
3:12:43 PMCheckbox 1 is checked
3:12:43 PMCheckbox 2 is checked
3:12:43 PMCheckbox 3 is checked

; ===============================================================================================================================
; SetChecked State      : Set checked state of Checkbox or Radio button
; ===============================================================================================================================
Func SetCheckedState($nCtrl, $iState)
    If $iState > 0 Then
        GUICtrlSetState($nCtrl, $GUI_CHECKED)
        If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
            GUICtrlSetData($log, _NowTime() & "Checkbox 1 is checked" & @CRLF, 1)
        EndIf
        If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
            GUICtrlSetData($log, _NowTime() & "Checkbox 2 is checked" & @CRLF, 1)
        EndIf
        If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then
            GUICtrlSetData($log, _NowTime() & "Checkbox 3 is checked" & @CRLF, 1)
        EndIf
    Else
        GUICtrlSetState($nCtrl, $GUI_UNCHECKED)
    EndIf
EndFunc   ;==>SetCheckedState

Full script -

#include <AutoItConstants.au3>
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <GUIImageList.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
Global $hGUI = GUICreate("Form", 500, 500, @DesktopWidth / 2 - 500 / 2, @DesktopHeight / 2 - 700 / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
Global $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 35, 25, 97, 17)
Global $Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 35, 45, 97, 17)
Global $Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 35, 65, 97, 17)
Global $Save = GUICtrlCreateButton("Save", 30, 95, 75, 25, 0)
GUICtrlSetOnEvent(-1, "SaveClick")
Global $Load = GUICtrlCreateButton("Load", 30, 130, 75, 25, 0)
GUICtrlSetOnEvent(-1, "LoadClick")
Global $Clear = GUICtrlCreateButton("Clear", 30, 165, 75, 25, 0)
GUICtrlSetOnEvent(-1, "ClearClick")
Global $log = GUICtrlCreateEdit("", 20, 285, 460, 200, BitOR($ES_WANTRETURN, $ES_READONLY, $ES_AUTOVSCROLL, $WS_VSCROLL))
GUICtrlSetFont($log, 12, 800, "verdana") ;Change Font Size to 12
GUICtrlSetBkColor($log, 0xFFFFFF)
GUICtrlSetColor($log, $COLOR_Green)
GUICtrlSetResizing(-1, 802)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func ClearClick()
    SetCheckedState($Checkbox1, 0)
    SetCheckedState($Checkbox2, 0)
    SetCheckedState($Checkbox3, 0)
EndFunc   ;==>ClearClick

Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

Func LoadClick()
    SetCheckedState($Checkbox1, IniRead(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox1", False))
    SetCheckedState($Checkbox2, IniRead(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox2", False))
    SetCheckedState($Checkbox3, IniRead(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox3", False))
EndFunc   ;==>LoadClick

Func SaveClick()
    IniWrite(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox1", IsChecked($Checkbox1))
    IniWrite(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox2", IsChecked($Checkbox2))
    IniWrite(@ScriptDir & "\cktest.ini", "checkboxes", "Checkbox3", IsChecked($Checkbox3))
EndFunc   ;==>SaveClick


; ===============================================================================================================================
; SetChecked State      : Set checked state of Checkbox or Radio button
; ===============================================================================================================================
Func SetCheckedState($nCtrl, $iState)
    If $iState > 0 Then
        GUICtrlSetState($nCtrl, $GUI_CHECKED)
        If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
            GUICtrlSetData($log, _NowTime() & "Checkbox 1 is checked" & @CRLF, 1)
        EndIf
        If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
            GUICtrlSetData($log, _NowTime() & "Checkbox 2 is checked" & @CRLF, 1)
        EndIf
        If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then
            GUICtrlSetData($log, _NowTime() & "Checkbox 3 is checked" & @CRLF, 1)
        EndIf
    Else
        GUICtrlSetState($nCtrl, $GUI_UNCHECKED)
    EndIf
EndFunc   ;==>SetCheckedState

; ===============================================================================================================================
; IsChecked             :Get checked state of Checkbox or Radio button
; ===============================================================================================================================
Func IsChecked($nCtrl)
    If BitAND(GUICtrlRead($nCtrl), $GUI_CHECKED) = $GUI_CHECKED Then Return 1
    Return 0
EndFunc   ;==>IsChecked

 

Link to comment
Share on other sites

  • Developers

Shouldn't that be:

; ===============================================================================================================================
; SetChecked State      : Set checked state of Checkbox or Radio button
; ===============================================================================================================================
Func SetCheckedState($nCtrl, $iState)
    If $iState > 0 Then
        GUICtrlSetState($nCtrl, $GUI_CHECKED)
        If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
            GUICtrlSetData($log, _NowTime() & "Checkbox 1 is checked" & @CRLF, 1)
        EndIf
    Else
        GUICtrlSetState($nCtrl, $GUI_UNCHECKED)
    EndIf
EndFunc   ;==>SetCheckedState

.. as you specify the controlhandle to check in the first parameter?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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