Sign in to follow this  
Followers 0
Moon

How to read which button is pressed?

4 posts in this topic

I seem to be too stupid to read from a simple window :)

I've got three checkboxes ($check1 to $check3) and an 'ok' and a 'cancel' button. So how do I make the script read which checkbox is check and which button is pressed? I seem to be unable to deduce from the examples in the help file. Thanks for any patience.

Share this post


Link to post
Share on other sites



I seem to be too stupid to read from a simple window  :)

I've got three checkboxes ($check1 to $check3) and an 'ok' and a 'cancel' button. So how do I make the script read which checkbox is check and which button is pressed? I seem to be unable to deduce from the examples in the help file. Thanks for any patience.

<{POST_SNAPBACK}>

Heres an example to get you started:

GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered
Opt("GUICoordMode", 1)
$check1 = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20)
$check2 = GUICtrlCreateCheckbox("CHECKBOX 2", 10, 25, 120, 20)
$check3 = GUICtrlCreateCheckbox("CHECKBOX 3", 10, 40, 120, 20)
$ok = GUICtrlCreateButton("OK", 10, 80, 50)
$Cancel = GUICtrlCreateButton("Cancel", 80,80,50)
GUISetState()      ; will display an  dialog box with 2 button
; Run the GUI until the dialog is closed
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = -3 
         ExitLoop
      Case $msg = $ok
         MsgBox(0, 'ok', 'ok pressed')
         ExitLoop
      Case $msg = $Cancel
         MsgBox(0, 'Cancel', 'cancel pressed')
         Exit
   EndSelect
Wend
If GUIRead($check1) = 1 Then MsgBox(0, "Check1", "Checked")
If GUIRead($check2) = 1 Then MsgBox(0, "Check2", "Checked")
If GUIRead($check3) = 1 Then MsgBox(0, "Check3", "Checked")

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Heres an example to get you started:

Select
     Case $msg = -3
Sorry for cutting in but I'm working on something similar and I seem to be unable to do it right. Where does the '-3' come from? Is it because there are 3 checkboxes that can return their state? So you get back a value that still has to be referenced by the use of if-conditions?

I do have 5 checkboxes + ok + cancel but it should be the same. In the following code I only use one checkbox to demonstrate:

; set default variables
logging = 1

$check1 = GUICtrlCreateCheckbox("Enable logging", 10, 10, 200, 20)
IF $logging = 1 then GUICtrlSetState ( $check1, $GUI_CHECKED) 

If GUIRead($check1) = 1 Then $logging = 1 Else $logging = 0

MsgBox(0, "Checkbox state", "logging: " & GUIRead($check1)

I do set defaults for all 5 checkboxes in the beginning and set the state of the checkboxes accordingly, the user can overwrite them by checking the boxes according to his preference. So in the above example the checkbox for 'logging' is checked.

Now what happens if the user unchecks it? Cause when I use the term 'if then else' as above I do get an 'Illegal text at the end of statement' error message. Does this mean I cannot combine these two possibilites but have to do them seperately?

If GUIRead($check1) = 1 Then $logging = 1
If GUIRead($check1) = 0 Then $logging = 0

If I do it like this and the user unchecks the box the variable $logging is assigned the value '4'. I'm confused.

And here's more, please correct me if I'm wrong: since I do have 5 checkboxes with two values each I have about 5^2 = 25 possibilities. How do I handle those with if/then?

if $check1 = 1 AND $check2 = 1 AND $check 3 = 1 AND $check4 = 1 AND $check5 = 1 do this
if $check1 = 0 AND $check2 = 0 AND $check 3 = 1 AND $check4 = 1 AND $check5 = 1 do that

And so on? Seems, I'm very far away from those lines programmers seem to think along :)


MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch

Share this post


Link to post
Share on other sites

-3 is the "magic value" returned by GuiGetMsg() when the user clicks the 'x' close button on the GUI window.

If GUIRead($check1) = 1 Then $logging = 1 Else $logging = 0 cannot be on one line. You must say:

If GUIRead($check1) = 1 Then
  $logging = 1
Else
  $logging = 0
EndIf

Do you really need to handle all 5^2 = 25 possibilities? If you do, there are some advanced tricks with Arrays and BitOr you could try....


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

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