Sign in to follow this  
Followers 0
Frit

Begginer question

9 posts in this topic

My question is simple: How do I get variable information from checkboxes and buttons?

I want to make the program knows when the check box (or button) is marked to do something I want.

Share this post


Link to post
Share on other sites



Here is how to get wether a checkbox or radio button is checked....

$GUI_UNCHECKED Radio or Checkbox will be unchecked

$GUI_CHECKED Radio or Checkbox will be checked

for buttons

While 1 ;Starts an INFINITE LOOP

$msg = GUIGetMsg() ;Listens to see if a control is pressed

case $msg = $YourButtonVariable ; If the control that is pressed is your button then.. note($YourButtonVariable is the variable you made your button in.. ex. $Button_1 = GUICtrlCreateButton())

ExecuteFunctionName() ;execute this function...

WEnd

Hope that helps

Share this post


Link to post
Share on other sites

If it's your own GUI, you'll use the $ sign before the creation to create the variable.

$GUI = GUICreate('Title')
$CheckBox1 = GUICtrlCreateCheckBox('CkBox', 10, 10)

GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = - 3 Then Exit
    If $msg = $CheckBox1 And GUICtrlRead($CheckBox1) = 1 Then
        MsgBox(0, '', 'You Checked the check box')
    EndIf
    Sleep(10)
Wend

If it's another application, look up ControlCommand() in the help file.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#include <GUIConstants.au3>
GUICreate("My GUI radio"); will create a dialog box that when displayed is centered

$radio1 = GUICtrlCreateRadio ("Radio 1", 10, 10, 120, 20)
GUICtrlSetState ($radio1,$GUI_CHECKED)
$radio2 = GUICtrlCreateRadio ("Radio 2", 10, 40, 120, 20)
$btn = GUICtrlCreateButton( "Test", 100, 100, 100, 20)
GUISetState ()   ; will display an  dialog box with 1 checkbox

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $btn Then
        If BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED Then
            MsgBox(0,"test", " Radio 1 was checked   ")
        ElseIf BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED Then
            MsgBox(0,"test", " Radio 2 was checked   ")
        EndIf
    EndIf
        
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

8)

getting slower am i

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

@Chris

Your script has an error.

I thinks it's with the "case" part.

Something about a "select".

Share this post


Link to post
Share on other sites

@Chris

Your script has an error.

I thinks it's with the "case" part.

Something about a "select".

Get on him!!! :o

Tell him to use [ code] [/ code] tags too while your at it!!


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Get on him!!! :o

Tell him to use [ code] [/ code] tags too while your at it!!

hahah... I did'nt even provide full code??????????

im confused....

what was the error message? i don't even have a case statement in their... lol

Edited by CHRIS95219

Share this post


Link to post
Share on other sites

Here is how to get wether a checkbox or radio button is checked....

$GUI_UNCHECKED Radio or Checkbox will be unchecked

$GUI_CHECKED Radio or Checkbox will be checked

for buttons

While 1 ;Starts an INFINITE LOOP

$msg = GUIGetMsg() ;Listens to see if a control is pressed

case $msg = $YourButtonVariable ; If the control that is pressed is your button then.. note($YourButtonVariable is the variable you made your button in.. ex. $Button_1 = GUICtrlCreateButton())

ExecuteFunctionName() ;execute this function...

WEnd

Hope that helps

hahah... I did'nt even provide full code??????????

im confused....

what was the error message? i don't even have a case statement in their... lol

This line sure looks like a case statement to me: case $msg = $YourButtonVariable

The rest of the guys posted code, so I'm not going to....

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

oh, woops, i did'nt see that.. sorry people...

While 1;Starts an INFINITE LOOP
$msg = GUIGetMsg();Listens to see if a control is pressed
select
case $msg = $YourButtonVariable; If the control that is pressed is your button then.. note($YourButtonVariable is the variable you made your button in.. ex. $Button_1 = GUICtrlCreateButton())
ExecuteFunctionName();execute this function...
EndSelect
WEnd

urrr, today is not my day...

Edited by CHRIS95219

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