Jump to content

If radio checked then...


 Share

Recommended Posts

Hi,

I'm trying to make a gui, but I have a problem about $GUI_ENABLE and $GUI_DISABLE of a GUICtrlCreateInput.

I'd like to enable it if $radioBz1 is $GUI_CHECKED and to disable it if $radioBz2 or $radioBz3 are $GUI_CHECKED.

As I have written in the code below, I see the GUICtrlCreateInput refresh and I don't like it..

This is my gui code

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

Local $msg, $tab
Local $tabA
    Local $radioAx1, $radioAx2
    Local $radioAy1, $radioAy2
Local $tabB
    Local $radioBx1, $radioBx2
    Local $radioBy1, $radioBy2
    Local $radioBz1, $radioBz2, $radioBz3
    Local $inputNAME
;##########|=> .: GUI START :. <=|##############################################
GUICreate("asd", 400, 300)
$tab = GUICtrlCreateTab(10, 10, 200, 230)
$tabA = GUICtrlCreateTabItem("A")
    GUICtrlCreateGroup("x", 15, 35, 90, 70)
        $radioAx1 = GUICtrlCreateRadio("1", 20, 55, 80, 20)
        $radioAx2 = GUICtrlCreateRadio("2", 20, 75, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("y", 110, 35, 90, 70)
        $radioAy1 = GUICtrlCreateRadio("1", 115, 55, 80, 20)
        $radioAy2 = GUICtrlCreateRadio("2", 115, 75, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
$tabB = GUICtrlCreateTabItem("B")
    GUICtrlCreateGroup("x", 15, 35, 90, 70)
        $radioBx1 = GUICtrlCreateRadio("1", 20, 55, 80, 20)
        $radioBx2 = GUICtrlCreateRadio("2", 20, 75, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("y", 110, 35, 90, 70)
        $radioBy1 = GUICtrlCreateRadio("1", 115, 55, 80, 20)
        $radioBy2 = GUICtrlCreateRadio("2", 115, 75, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("z", 15, 110, 90, 90)
        $radioBz1 = GUICtrlCreateRadio("1", 20, 130, 80, 20)
        $radioBz2 = GUICtrlCreateRadio("2", 20, 150, 80, 20)
        $radioBz3 = GUICtrlCreateRadio("3", 20, 170, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("N", 110, 110, 90, 50)
        $inputNAME = GUICtrlCreateInput("", 115, 130, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
GUICtrlCreatePic("800x600.jpg", 0, 0, 400, 300, $WS_CLIPSIBLINGS)
GUISetState(-1,$GUI_ONTOP)
;##########|=> .: GUI END :. <=|################################################

;##########|=> .: GUI FUNCTION :. <=|###########################################
_GUI()

Func _GUI()
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        If BitAnd(GUICtrlRead($radioBz1), $GUI_CHECKED) Then GUICtrlSetState($inputNAME, $GUI_ENABLE)
        If BitAnd(GUICtrlRead($radioBz2), $GUI_CHECKED) Then GUICtrlSetState($inputNAME, $GUI_DISABLE)
        If BitAnd(GUICtrlRead($radioBz3), $GUI_CHECKED) Then GUICtrlSetState($inputNAME, $GUI_DISABLE)
    WEnd
EndFunc
Edited by Zodiak
Link to comment
Share on other sites

Hi,

I'm trying to make a gui, but I have a problem about $GUI_ENABLE and $GUI_DISABLE of a GUICtrlCreateInput.

I'd like to enable it if $radioBz1 is $GUI_CHECKED and to disable it if $radioBz2 or $radioBz3 are $GUI_CHECKED.

As I have written in the code below, I see the GUICtrlCreateInput refresh and I don't like it..

This is my gui code

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

Local $msg, $tab
Local $tabA
    Local $radioAx1, $radioAx2
    Local $radioAy1, $radioAy2
Local $tabB
    Local $radioBx1, $radioBx2
    Local $radioBy1, $radioBy2
    Local $radioBz1, $radioBz2, $radioBz3
    Local $inputNAME
;##########|=> .: GUI START :. <=|##############################################
GUICreate("asd", 400, 300)
$tab = GUICtrlCreateTab(10, 10, 200, 230)
$tabA = GUICtrlCreateTabItem("A")
    GUICtrlCreateGroup("x", 15, 35, 90, 70)
        $radioAx1 = GUICtrlCreateRadio("1", 20, 55, 80, 20)
        $radioAx2 = GUICtrlCreateRadio("2", 20, 75, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("y", 110, 35, 90, 70)
        $radioAy1 = GUICtrlCreateRadio("1", 115, 55, 80, 20)
        $radioAy2 = GUICtrlCreateRadio("2", 115, 75, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
$tabB = GUICtrlCreateTabItem("B")
    GUICtrlCreateGroup("x", 15, 35, 90, 70)
        $radioBx1 = GUICtrlCreateRadio("1", 20, 55, 80, 20)
        $radioBx2 = GUICtrlCreateRadio("2", 20, 75, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("y", 110, 35, 90, 70)
        $radioBy1 = GUICtrlCreateRadio("1", 115, 55, 80, 20)
        $radioBy2 = GUICtrlCreateRadio("2", 115, 75, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("z", 15, 110, 90, 90)
        $radioBz1 = GUICtrlCreateRadio("1", 20, 130, 80, 20)
        $radioBz2 = GUICtrlCreateRadio("2", 20, 150, 80, 20)
        $radioBz3 = GUICtrlCreateRadio("3", 20, 170, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("N", 110, 110, 90, 50)
        $inputNAME = GUICtrlCreateInput("", 115, 130, 80, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
GUICtrlCreatePic("800x600.jpg", 0, 0, 400, 300, $WS_CLIPSIBLINGS)
GUISetState(-1,$GUI_ONTOP)
;##########|=> .: GUI END :. <=|################################################

;##########|=> .: GUI FUNCTION :. <=|###########################################
_GUI()

Func _GUI()
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        If BitAnd(GUICtrlRead($radioBz1), $GUI_CHECKED) Then GUICtrlSetState($inputNAME, $GUI_ENABLE)
        If BitAnd(GUICtrlRead($radioBz2), $GUI_CHECKED) Then GUICtrlSetState($inputNAME, $GUI_DISABLE)
        If BitAnd(GUICtrlRead($radioBz3), $GUI_CHECKED) Then GUICtrlSetState($inputNAME, $GUI_DISABLE)
    WEnd
EndFunc
Func _GUI()
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $radioBz1
                If BitAND(GUICtrlRead($radioBz1), $GUI_CHECKED) Then GUICtrlSetState($inputNAME, $GUI_ENABLE)
            Case $radioBz2
                If BitAND(GUICtrlRead($radioBz2), $GUI_CHECKED) Then GUICtrlSetState($inputNAME, $GUI_DISABLE)
            Case $radioBz3
                If BitAND(GUICtrlRead($radioBz3), $GUI_CHECKED) Then GUICtrlSetState($inputNAME, $GUI_DISABLE)
        EndSwitch
    WEnd
EndFunc   ;==>_GUI
Link to comment
Share on other sites

As Yashied has shown.

Your problem was simply that you kept setting the state even when there was no need. Here is a chnage to your code which uses the same approach but remembers if the state needs to be changed or not.

#include <GUIConstantsEx.au3>
 #include <WindowsConstants.au3>
 
 Local $msg, $tab
 Local $tabA
 Local $radioAx1, $radioAx2
 Local $radioAy1, $radioAy2
 Local $tabB
 Local $radioBx1, $radioBx2
 Local $radioBy1, $radioBy2
 Local $radioBz1, $radioBz2, $radioBz3
 Local $inputNAME
 Global $IPen = True
;##########|=> .: GUI START :. <=|##############################################
 GUICreate("asd", 400, 300)
 $tab = GUICtrlCreateTab(10, 10, 200, 230)
 $tabA = GUICtrlCreateTabItem("A")
 GUICtrlCreateGroup("x", 15, 35, 90, 70)
 $radioAx1 = GUICtrlCreateRadio("1", 20, 55, 80, 20)
 $radioAx2 = GUICtrlCreateRadio("2", 20, 75, 80, 20)
 GUICtrlCreateGroup("", -99, -99, 1, 1)
 GUICtrlCreateGroup("y", 110, 35, 90, 70)
 $radioAy1 = GUICtrlCreateRadio("1", 115, 55, 80, 20)
 $radioAy2 = GUICtrlCreateRadio("2", 115, 75, 80, 20)
 GUICtrlCreateGroup("", -99, -99, 1, 1)
 $tabB = GUICtrlCreateTabItem("B")
 GUICtrlCreateGroup("x", 15, 35, 90, 70)
 $radioBx1 = GUICtrlCreateRadio("1", 20, 55, 80, 20)
 $radioBx2 = GUICtrlCreateRadio("2", 20, 75, 80, 20)
 GUICtrlCreateGroup("", -99, -99, 1, 1)
 GUICtrlCreateGroup("y", 110, 35, 90, 70)
 $radioBy1 = GUICtrlCreateRadio("1", 115, 55, 80, 20)
 $radioBy2 = GUICtrlCreateRadio("2", 115, 75, 80, 20)
 GUICtrlCreateGroup("", -99, -99, 1, 1)
 GUICtrlCreateGroup("z", 15, 110, 90, 90)
 $radioBz1 = GUICtrlCreateRadio("1", 20, 130, 80, 20)
 $radioBz2 = GUICtrlCreateRadio("2", 20, 150, 80, 20)
 $radioBz3 = GUICtrlCreateRadio("3", 20, 170, 80, 20)
 GUICtrlCreateGroup("", -99, -99, 1, 1)
 GUICtrlCreateGroup("N", 110, 110, 90, 50)
 $inputNAME = GUICtrlCreateInput("", 115, 130, 80, 20)
 GUICtrlCreateGroup("", -99, -99, 1, 1)
 GUICtrlCreateTabItem("")
 GUISetState(@SW_SHOW)
 GUICtrlCreatePic("800x600.jpg", 0, 0, 400, 300, $WS_CLIPSIBLINGS)
 GUISetState(-1, $GUI_ONTOP)
;##########|=> .: GUI END :. <=|################################################
 
;##########|=> .: GUI FUNCTION :. <=|###########################################
 _GUI()
 
 Func _GUI()
     While 1
         $msg = GUIGetMsg()
         If $msg = $GUI_EVENT_CLOSE Then ExitLoop
         If BitAND(GUICtrlRead($radioBz1), $GUI_CHECKED) Then
             If Not $IPen Then
                 GUICtrlSetState($inputNAME, $GUI_ENABLE)
                 $IPen = True
             EndIf
         Else
             If $IPen Then
                 GUICtrlSetState($inputNAME, $GUI_DISABLE)
                 $IPen = False
             EndIf
         EndIf
     WEnd
 EndFunc ;==>_GUI

Welcome to the AutoIt forums :)

Edit: Corrected spelling of Yashied!

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...