Jump to content

Making a Check Box Update A Label


Recommended Posts

So, the title shows it all, I've been trying multiple things, but can't seem to get it down. The current issue I'm working on is simply getting the Check Box when checked to change the label of "ADebugVar" to read "It working". This is what I have so far, and I'm aware it's a mess, I'm currently more or less trying things to see what works, so it's not going to be neat, or perfect.

 

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>

Test()  

Func Test()
    Local $hGUI = GUICreate("Break Reminders")
    Local $idClose = GUICtrlCreateButton("Exit", 310, 370, 85, 25)
    Local $idApplyTimes = GuiCtrlCreateCheckbox("Apply Times", 5, 370, 85, 25)
    $now = @HOUR & ":" & @MIN & ":" & @SEC
    $CurrentTime = GUICtrlCreateLabel($now, 175, 10, 120, 20)
    $Break1 = GUICtrlCreateLabel("Break 1 Time", 40, 85, -1, -1)
    $Break1Time = GUICtrlCreateInput("00:00:00", 40, 100, -1, -1)
    $Lunch = GUICtrlCreateLabel("Lunch Time", 40, 150, -1, -1)
    $LunchTime = GUICtrlCreateInput("00:00:00", 40, 165, -1, -1)
    $Break3 = GUICtrlCreateLabel("Break 3 Time", 40, 210, -1, -1)
    $Break3Time = GUICtrlCreateInput("00:00:00", 40, 225, -1, -1)
    $ClockOut = GUICtrlCreateLabel("Clock Out Time", 40, 275, -1, -1)
    $ClockOutTime = GUICtrlCreateInput("00:00:00", 40, 290, -1, -1)
    $DebugVariableText = GUICTRLCreateLabel("DebugVariable", 160, 345, -1, -1)
    $ADebugVar = GUICtrlCreateLabel("DebugText", 160, 370, -1, -1)
    
    Global $Var1, $Var2
        ; Display the GUI.
    
    GUISetState(@SW_SHOW, $hGUI)
        ; Loop until the user exits.
    While 1
            If $now <> @HOUR & ":" & @MIN & ":" & @SEC Then
                $now = @HOUR & ":" & @MIN & ":" & @SEC
                GUICtrlSetData($CurrentTime, $now)
            EndIf
        Switch GUIGetMsg()
            Case $idApplyTimes
                If _IsChecked($idApplyTimes) Then
                    GUICtrlSetData($ADebugVar, "It working")
                    If $now <> @HOUR & ":" & @MIN & ":" & @SEC Then
                    [ENTER MAIN CODE HERE]
                    EndIf
                    ;MsgBox($MB_SYSTEMMODAL, "", "The checkbox is checked.", 0, $hGUI)
                EndIf
                
            Case $GUI_EVENT_CLOSE, $idClose 
                ExitLoop
            
        EndSwitch
            
    WEnd
    

    
    
EndFunc ; Test


Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

 

EDIT: If any pros in coding have any helpful advice in things that could be optimized better, feel free to poke fun at my code. Or if there was a better way to post this or a better place to post it, feel free to let me know.

Edited by JustCallMeAlec
Link to comment
Share on other sites

55 minutes ago, JustCallMeAlec said:

The current issue I'm working on is simply getting the Check Box when checked to change the label of "ADebugVar" to read "It working".

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>

;Define GUI
Global $hGUI = GUICreate("Break Reminders")
Global $idExitButton = GUICtrlCreateButton("Exit", 310, 370, 85, 25)
Global $idApplyTimes = GuiCtrlCreateCheckbox("Apply Times", 5, 370, 85, 25)
Global $now = @HOUR & ":" & @MIN & ":" & @SEC
Global $CurrentTime = GUICtrlCreateLabel($now, 175, 10, 120, 20)
Global $Break1 = GUICtrlCreateLabel("Break 1 Time", 40, 85, -1, -1)
Global $Break1Time = GUICtrlCreateInput("00:00:00", 40, 100, -1, -1)
Global $Lunch = GUICtrlCreateLabel("Lunch Time", 40, 150, -1, -1)
Global $LunchTime = GUICtrlCreateInput("00:00:00", 40, 165, -1, -1)
Global $Break3 = GUICtrlCreateLabel("Break 3 Time", 40, 210, -1, -1)
Global $Break3Time = GUICtrlCreateInput("00:00:00", 40, 225, -1, -1)
Global $ClockOut = GUICtrlCreateLabel("Clock Out Time", 40, 275, -1, -1)
Global $ClockOutTime = GUICtrlCreateInput("00:00:00", 40, 290, -1, -1)
Global $DebugVariableText = GUICTRLCreateLabel("DebugVariable", 160, 345, -1, -1)
Global $ADebugVar = GUICtrlCreateLabel("DebugText", 160, 370, -1, -1)


Test()

Func Test()
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ;Register function to update time every second
    AdlibRegister(update_time, 1000)

    ; Loop until the user exits.
    While 1

        Switch GUIGetMsg()
            Case $idApplyTimes
                ;If checkbox is checked
                If GUICtrlRead($idApplyTimes) = $GUI_CHECKED  Then
                    GUICtrlSetData($ADebugVar, "It working")
                Else
                    GUICtrlSetData($ADebugVar, "")
                EndIf

            Case $GUI_EVENT_CLOSE, $idExitButton
                ExitLoop
        EndSwitch

    WEnd

    ;Unregister function to update time every second
    AdlibUnRegister(update_time)
EndFunc ; Test

Func update_time()
    GUICtrlSetData($CurrentTime, @HOUR & ":" & @MIN & ":" & @SEC)
EndFunc

@JustCallMeAlec

***   Edit   ***

I added a few comments and modified the script a little.

Edited by TheXman
Made GUI global / Added adlib to update time
Link to comment
Share on other sites

3 hours ago, TheXman said:
#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>

;Define GUI
Global $hGUI = GUICreate("Break Reminders")
Global $idExitButton = GUICtrlCreateButton("Exit", 310, 370, 85, 25)
Global $idApplyTimes = GuiCtrlCreateCheckbox("Apply Times", 5, 370, 85, 25)
Global $now = @HOUR & ":" & @MIN & ":" & @SEC
Global $CurrentTime = GUICtrlCreateLabel($now, 175, 10, 120, 20)
Global $Break1 = GUICtrlCreateLabel("Break 1 Time", 40, 85, -1, -1)
Global $Break1Time = GUICtrlCreateInput("00:00:00", 40, 100, -1, -1)
Global $Lunch = GUICtrlCreateLabel("Lunch Time", 40, 150, -1, -1)
Global $LunchTime = GUICtrlCreateInput("00:00:00", 40, 165, -1, -1)
Global $Break3 = GUICtrlCreateLabel("Break 3 Time", 40, 210, -1, -1)
Global $Break3Time = GUICtrlCreateInput("00:00:00", 40, 225, -1, -1)
Global $ClockOut = GUICtrlCreateLabel("Clock Out Time", 40, 275, -1, -1)
Global $ClockOutTime = GUICtrlCreateInput("00:00:00", 40, 290, -1, -1)
Global $DebugVariableText = GUICTRLCreateLabel("DebugVariable", 160, 345, -1, -1)
Global $ADebugVar = GUICtrlCreateLabel("DebugText", 160, 370, -1, -1)


Test()

Func Test()
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ;Register function to update time every second
    AdlibRegister(update_time, 1000)

    ; Loop until the user exits.
    While 1

        Switch GUIGetMsg()
            Case $idApplyTimes
                ;If checkbox is checked
                If GUICtrlRead($idApplyTimes) = $GUI_CHECKED  Then
                    GUICtrlSetData($ADebugVar, "It working")
                Else
                    GUICtrlSetData($ADebugVar, "")
                EndIf

            Case $GUI_EVENT_CLOSE, $idExitButton
                ExitLoop
        EndSwitch

    WEnd

    ;Unregister function to update time every second
    AdlibUnRegister(update_time)
EndFunc ; Test

Func update_time()
    GUICtrlSetData($CurrentTime, @HOUR & ":" & @MIN & ":" & @SEC)
EndFunc

@JustCallMeAlec

***   Edit   ***

I added a few comments and modified the script a little.

Nice, dude! But another thing came up, now I'm trying to get it to check continuously every second while the check box is checked for a variable to be equal to something, any advice on this one?  This is what that brought me to:

 

Quote
#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>

Test()  

Func Test()
    Local $hGUI = GUICreate("Break Reminders")
    Local $idClose = GUICtrlCreateButton("Exit", 310, 370, 85, 25)
    Local $idApplyTimes = GuiCtrlCreateCheckbox("Apply Times", 5, 370, 85, 25)
    Local $NB1 = 0
    Local $NL = 0
    Local $NB3 = 0
    Local $NCO = 0
    Local $SecT = 1
    Local $Changed = 0
    $now = @HOUR & ":" & @MIN & ":" & @SEC
    $nowF = @HOUR & @MIN & @SEC
    $CurrentTime = GUICtrlCreateLabel($now, 175, 10, 120, 20)
    $CurrentTime2 = GUICtrlCreateLabel($nowF, 175, 25, 120, 20)
    $Break1 = GUICtrlCreateLabel("Break 1 Time", 40, 85, -1, -1)
    $Break1Time = GUICtrlCreateInput("00:00:00", 40, 100, -1, -1)
    $Lunch = GUICtrlCreateLabel("Lunch Time", 40, 150, -1, -1)
    $LunchTime = GUICtrlCreateInput("00:00:00", 40, 165, -1, -1)
    $Break3 = GUICtrlCreateLabel("Break 3 Time", 40, 210, -1, -1)
    $Break3Time = GUICtrlCreateInput("00:00:00", 40, 225, -1, -1)
    $ClockOut = GUICtrlCreateLabel("Clock Out Time", 40, 275, -1, -1)
    $ClockOutTime = GUICtrlCreateInput("00:00:00", 40, 290, -1, -1)
    ;$DebugVariableText = GUICTRLCreateLabel("DebugVariable", 160, 345, -1, -1)
    $ADebugVar = GUICtrlCreateLabel("DebugText", 160, 345, 120, 50)
    
    Global $Var1, $Var2
        ; Display the GUI.
    
    GUISetState(@SW_SHOW, $hGUI)
        ; Loop until the user exits.
    While 1
            If $now <> @HOUR & ":" & @MIN & ":" & @SEC Then
                $now = @HOUR & ":" & @MIN & ":" & @SEC
                $nowF = @HOUR & @MIN & @SEC
                GUICtrlSetData($CurrentTime, $now)
                GUICtrlSetData($CurrentTIme2, $nowF)
            EndIf
        Switch GUIGetMsg()
            Case $idApplyTimes
                If GUICtrlRead($idApplyTimes) = $GUI_CHECKED Then
                ;   GUICtrlSetData($ADebugVar, "It working")
                    If $nowF < 220000 Then
                        GUICtrlSetData($ADebugVar, "Not After Break 1")
                    EndIf
                    
                    If  $nowF > 220000 Then
                    GUICtrlSetData($ADebugVar, "After Break 1") 
                    EndIf
                    
                    ;MsgBox($MB_SYSTEMMODAL, "", "The checkbox is checked.", 0, $hGUI)

            EndIf   
                If GUICtrlRead($idApplyTimes) <> $GUI_CHECKED Then
                    GUICtrlSetData($ADebugVar, "Debug Text")
                EndIf
            Case $GUI_EVENT_CLOSE, $idClose 
                ExitLoop
            
        EndSwitch
            
    WEnd
    

    ;Unregister function to update time every second
    AdlibUnRegister(update_time)
    
EndFunc ; Test

Func update_time()
    GUICtrlSetData($CurrentTime, @HOUR & ":" & @MIN & ":" & @SEC)
EndFunc

 

 

Link to comment
Share on other sites

On 5/5/2021 at 9:01 PM, JustCallMeAlec said:

Nice, dude! But another thing came up, now I'm trying to get it to check continuously every second while the check box is checked for a variable to be equal to something, any advice on this one?

 

Since you haven't read the PM I sent you yet, I will put the gist of it here.

The 3 reasons why I ignored you:

  1. If someone volunteers their time and expertise to help you, the first thing you should do is show some semblance of appreciation -- especially if you want (or might want) further assistance.  Something as simple as thanks will usually suffice.  Not doing so, will get you ignored.
     
  2. My name on this forum is TheXman,  not "dude".  Referring to me as "dude", "bro", "homie", or anything else other than my name, will most likely get you ignored.   Since you never know who you are speaking with, it is always better to err on the side of being too formal than too casual.
     
  3. If I can help it, I no longer shoot at moving targets.  So I don't play that "But another thing came up" or "one more thing" game.  Usually that's just a lazy person's way to try to get others to write their script for them piece-by-piece, step-by-step. Or, it's a sign that the person hasn't fully thought out what it is they want and is trying to do it on the fly.  Either way. I'm not going to allow you to waste my time.  There are plenty of people on the forum that'll write your scripts for you or play that game, but I'm not one of them.  I'm only interested in helping people learn how to help themselves, not to do it for them. 

    If you have a larger goal in mind, then explain what you are trying to accomplish in detail, show what you've tried, and ask for help with whatever is giving you problems.  Then, take the time to learn from the advice you are given and continue making progress towards you goal.  If you hit another obstacle, then repeat the previous process until you reach your goal.

You probably could also benefit by reading the 2 links in my signature that refer to how to get better answers to your technical questions.

Edited by TheXman
Fix typos
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...