Jump to content

Recommended Posts

Posted

I want to show or hide a edit control depending if a radio button is checked or not.The following Autoit code appears semantically ok but not working.Can anyone please help?

thanks

olmar

While 1
   $nMsg = GUIGetMsg()
   $isradioChk=GUICtrlRead($radio_AbsP);checked=1,not checked=4
   Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $isradioChk
         If $isradioChk<==1 Then
            GUICtrlSetState($edit_AbsP,$GUI_SHOW)
            GUICtrlSetState($edit_RelP,$GUI_HIDE)
         Else
            GUICtrlSetState($edit_AbsP,$GUI_HIDE)
            GUICtrlSetState($edit_RelP,$GUI_SHOW)
        EndIf
    Case $usrPrefs

    EndSwitch
WEnd

 

Posted

You where almost there.

This will get the job done for you.

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $radio_AbsP
        $isradioChk=GUICtrlRead($radio_AbsP);checked=1,not checked=4
         If $isradioChk = 1 Then
            GUICtrlSetState($edit_AbsP,$GUI_SHOW)
            GUICtrlSetState($edit_RelP,$GUI_HIDE)
         Else
            GUICtrlSetState($edit_AbsP,$GUI_HIDE)
            GUICtrlSetState($edit_RelP,$GUI_SHOW)
        EndIf
    Case $usrPrefs

    EndSwitch
WEnd

 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Posted (edited)

Hi Bowmore,

Thanks for the quick reply.Tried out your code but still both the edit ctrls visible as before.Below is the full code including the code you have proposed.Please have a look.

thanks

olmar

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=e:\projectbzt\usrprefs.kxf
$usrPrefs = GUICreate("User Preferences", 531, 271, 317, 119)
GUISetBkColor(0xD6D8C7)
$Group1 = GUICtrlCreateGroup("Group1", 19, 7, 242, 68)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$radio_AbsP = GUICtrlCreateRadio("Abselute Value", 83, 24, 105, 17, BitOR($GUI_SS_DEFAULT_RADIO,$BS_RIGHTBUTTON,$BS_RIGHT))
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$radio_RelPos = GUICtrlCreateRadio("Relative Value", 68, 47, 120, 17, BitOR($GUI_SS_DEFAULT_RADIO,$BS_RIGHTBUTTON,$BS_RIGHT))
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$edit_AbsP = GUICtrlCreateEdit("", 190, 21, 65, 21, $ES_CENTER)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xC4C7AD)
$edit_RelP = GUICtrlCreateEdit("", 190, 45, 65, 22, $ES_CENTER)
GUICtrlSetData(-1, 100)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xC4C7AD)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $radio_AbsP
        $isradioChk=GUICtrlRead($radio_AbsP);checked=1,not checked=4
         If $isradioChk = 1 Then
            GUICtrlSetState($edit_AbsP,$GUI_SHOW)
            GUICtrlSetState($edit_RelP,$GUI_HIDE)
         Else
            GUICtrlSetState($edit_AbsP,$GUI_HIDE)
            GUICtrlSetState($edit_RelP,$GUI_SHOW)
        EndIf
    Case $usrPrefs

    EndSwitch
WEnd

 

Edited by olmanRvr
Posted

Only 1 of the checkboxes was being monitored in the message loop

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=e:\projectbzt\usrprefs.kxf
$usrPrefs = GUICreate("User Preferences", 531, 271, 317, 119)
GUISetBkColor(0xD6D8C7)
$Group1 = GUICtrlCreateGroup("Group1", 19, 7, 242, 68)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$radio_AbsP = GUICtrlCreateRadio("Abselute Value", 83, 24, 105, 17, BitOR($GUI_SS_DEFAULT_RADIO,$BS_RIGHTBUTTON,$BS_RIGHT))
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$radio_RelPos = GUICtrlCreateRadio("Relative Value", 68, 47, 120, 17, BitOR($GUI_SS_DEFAULT_RADIO,$BS_RIGHTBUTTON,$BS_RIGHT))
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$edit_AbsP = GUICtrlCreateEdit("", 190, 21, 65, 21, $ES_CENTER)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xC4C7AD)
GUICtrlSetState($edit_AbsP,$GUI_HIDE) ;<=== as $radio_RelPos is initially checked, hide $edit_AbsP
$edit_RelP = GUICtrlCreateEdit("", 190, 45, 65, 22, $ES_CENTER)
GUICtrlSetData(-1, 100)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xC4C7AD)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $radio_AbsP,$radio_RelPos ;<== check state when either checkbox is changed
        $isradioChk=GUICtrlRead($radio_AbsP);checked=1,not checked=4
         If $isradioChk = 1 Then
            GUICtrlSetState($edit_AbsP,$GUI_SHOW)
            GUICtrlSetState($edit_RelP,$GUI_HIDE)
         Else
            GUICtrlSetState($edit_AbsP,$GUI_HIDE)
            GUICtrlSetState($edit_RelP,$GUI_SHOW)
        EndIf
    Case $usrPrefs

    EndSwitch
WEnd

 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Posted (edited)

Thanks Very much Bowmore!!

 Now it is working fine.Issue is SOLVED.For others having similar issue here is the correct code.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=e:\projectbzt\usrprefs.kxf
$usrPrefs = GUICreate("User Preferences", 531, 271, 317, 119)
GUISetBkColor(0xD6D8C7)
$Group1 = GUICtrlCreateGroup("Group1", 19, 7, 242, 68)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$radio_AbsP = GUICtrlCreateRadio("Abselute Value", 83, 24, 105, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$radio_RelP = GUICtrlCreateRadio("Relative Value", 68, 47, 120, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$edit_AbsP = GUICtrlCreateEdit("", 190, 21, 65, 21, $ES_CENTER)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xC4C7AD)
GUICtrlSetState(-1,$GUI_HIDE)
$edit_RelP = GUICtrlCreateEdit("", 190, 45, 65, 22, $ES_CENTER)
GUICtrlSetData(-1, 100)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xC4C7AD)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $radio_AbsP,$radio_RelP
            $isradioAbsChk=GUICtrlRead($radio_AbsP);checked=1,not checked=4
            $isradioRelChk=GUICtrlRead($radio_RelP);checked=1,not checked=4

             If $isradioAbsChk = 1 Then
                 GUICtrlSetState($edit_AbsP,$GUI_SHOW)
                 GUICtrlSetState($edit_RelP,$GUI_HIDE)
             Else
                  GUICtrlSetState($edit_AbsP,$GUI_HIDE)
                  GUICtrlSetState($edit_RelP,$GUI_SHOW)
            EndIf
    EndSwitch
WEnd

 

Edited by olmanRvr

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
×
×
  • Create New...