Sign in to follow this  
Followers 0
Monty

Checkboxes and default data

4 posts in this topic

Can someone help me with this one please?

** SEE EXAMPLE **

1. When the checkbox is not checked, I can modify text in the inputbox...all good!

2. When I check the checkbox, inputbox is set with dafault data "Test message!"...all good!

Now question: is there a way to modify this script so that I can change the inputbox data from "Test message!" to anything else without unchecking the checkbox.

YOUR HELP WILL BE APPRECIATED. THANK YOU. Monty.

#include <GUIConstantsEx.au3>
$guimain = GUICreate("Test", 300, 145)
$testcbox = GUICtrlCreateCheckbox("Test Checkbox", 30, 32, 97, 17)
$testinput = GUICtrlCreateInput("", 30, 64, 121, 21)
GUISetState(@SW_SHOW)
Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
        Case GUICtrlRead($testcbox) = $GUI_CHECKED
            GUICtrlSetData($testinput, "Test message!")
    EndSelect
Until Not WinExists($guimain)

Share this post


Link to post
Share on other sites



Your problem is that the script is continually updating the test in the input box to the test text. You need to make it only set the text once after the checkbox is checked. See the modified script below.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$guimain = GUICreate("Test", 300, 145)
$testcbox = GUICtrlCreateCheckbox("Test Checkbox", 30, 32, 97, 17)
$testinput = GUICtrlCreateInput("", 30, 64, 121, 21)
GUISetState(@SW_SHOW)
$unchecked = True
Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
        Case GUICtrlRead($testcbox) == $GUI_CHECKED And $unchecked==True
            GUICtrlSetData($testinput, "Test message!")
            $unchecked = False
        Case GUICtrlRead($testcbox) == $GUI_UNCHECKED
            $unchecked = True
    EndSelect
    Sleep(15)
Until Not WinExists($guimain)

_________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Simpler way:

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

$guimain = GUICreate("Test", 300, 145)
$testcbox = GUICtrlCreateCheckbox("Test Checkbox", 30, 32, 97, 17)
$testinput = GUICtrlCreateInput("", 30, 64, 121, 21)
GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    GUIDelete()
    Case $msg = $testcbox
    If GUICtrlRead($testcbox) = $GUI_CHECKED Then GUICtrlSetData($testinput, "Test message!")
    EndSelect
Until Not WinExists($guimain)
Edited by Zedna

Share this post


Link to post
Share on other sites

Thank you for both examples. Has definately solved my issues.

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  
Followers 0