Jump to content
Sign in to follow this  
Zag8888

[SOLVED] $GUI_CHECKED Little problem

Recommended Posts

Hey folks, I have a little problem with my script.

I have no experience with these things, and I know for¬† sure that my code is not the best, but please be lenient, thanks ūüėÖ

The User should first choose 1 of the 2 Options to actually start the script. If 1 of the 2 Option is choosen then the User should click start again and all should work.

I have already commented the problem, If the button Start is clicked before, the User will select just 1 of the 2 option and the program will start (Without clicking start).How can I set $Start to $GUI_UNCHECKED? I have already tried to use GuiCtrlSetState, but didnt worked.

 

$Start = GuiCtrlCreateButton("Start", 20, 200, 90, 50,bitor($BS_CENTER,0,0))
GUICtrlSetOnEvent($Start,"Startallrun")
Func Startallrun()
   If ((GUICtrlRead($Option1) = $GUI_UNCHECKED) And (GUICtrlRead($Option2) = $GUI_UNCHECKED)) Then
         MsgBox($MB_OK, "Error", "You have to select 1 Option")
         While (GUICtrlRead($Option1) = $GUI_UNCHECKED)
            Sleep(10)
            If (GUICtrlRead($Option1) = $GUI_CHECKED) Or (GUICtrlRead($Option2) = $GUI_CHECKED) Then
            GUICtrlSetState($Start,$GUI_UNCHECKED) ; This doesen't work for Buttons
               While (GUICtrlRead($Start) = $GUI_UNCHECKED)
                  Sleep(10)
                  If ($Start = $GUI_CHECKED) Then ; That's the problem. The script will start if I click one of the 2 options (because start was already checked before)
                     ExitLoop
                  EndIf
               WEnd
               ExitLoop
            EndIf
         WEnd
      Else
         If (GUICtrlRead($Option1) = $GUI_CHECKED) Then
            MsgBox($MB_OK, "Starting", "Start")
            Start()
         EndIf
      EndIf
EndFunc

 

Edited by Zag8888
Solved

Share this post


Link to post
Share on other sites

Zag8888,

Firstly, how about posting some runnable code rather then a snippet. Then, how about explaining what you are trying to do and what is not working so we can see how we might help you. At the moment it is a bit hard to offer suggestions when we have no idea where the problem actually lies.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hello Melba23, I have added some more info in the thread.

I really don't understand how to Uncheck a button, I have tried to use GUICtrlSetState, but it doesen't worked for me

Edited by Melba23
Merged and quotes removed

Share this post


Link to post
Share on other sites

Zag8888,

I did say "runnable" code - all we have is a function and button creation/assignment. Where are the GUI. the $StoryMode and $Option1 controls, etc?

And what exactly do you mean by "unchecking" a button - you check/uncheck radios and checkboxes, not normal buttons.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
15 minutes ago, Melba23 said:

Zag8888,

I did say "runnable" code - all we have is a function and button creation/assignment. Where are the GUI. the $StoryMode and $Option1 controls, etc?

And what exactly do you mean by "unchecking" a button - you check/uncheck radios and checkboxes, not normal buttons.

M23

$StoryMode,$Option1 and $Option2 are just Radio.

 

When I click Start the Function Start() will run, but only if 1 of these 3 radio are selected, after I select 1 option the code will start immediately (Without waiting for the click start again).

 

Share this post


Link to post
Share on other sites

Just disable the $Start button, then use an GuiSetOnEvent for $Option1 and $Option2 to enable the start button e.g. this way, they must choose one of the options before pushing the start button.  Also for the Startallrun() function you only need to know which option is checked see example below.
nb: I've prefixed my variables with $id to show that they're control ids.

idOption1 = GUICtrlCreateRadio("Option 1", 10, 10, 120, 20)
    GUICtrlSetOnEvent($idOption1,"_EnableStart")
$idOption2 = GUICtrlCreateRadio("Option 2", 10, 40, 120, 20)
    GUICtrlSetOnEvent($idOption2,"_EnableStart")
$idStart = GuiCtrlCreateButton("Select Radio Above", 10, 70, 120, 50,bitor($BS_CENTER,0,0))
    GUICtrlSetOnEvent($idStart,"Startallrun")
    GUICtrlSetState($idStart, $GUI_DISABLE)

Func _EnableStart()
    GUICtrlSetState($idStart, $GUI_ENABLE)
EndFunc

Func Startallrun()
    If GUICtrlRead($idOption1) = $GUI_CHECKED Then
        MsgBox(4096, "Starting", "Running Option 1")
    ElseIf GUICtrlRead($idOption2) = $GUI_CHECKED Then
        MsgBox(4096, "Starting", "Running Option 2")
    EndIf
EndFunc

 

Share this post


Link to post
Share on other sites
3 minutes ago, Subz said:

Just disable the $Start button, then use an GuiSetOnEvent for $Option1 and $Option2 to enable the start button e.g. this way, they must choose one of the options before pushing the start button.  Also for the Startallrun() function you only need to know which option is checked see example below.
nb: I've prefixed my variables with $id to show that they're control ids.

idOption1 = GUICtrlCreateRadio("Option 1", 10, 10, 120, 20)
    GUICtrlSetOnEvent($idOption1,"_EnableStart")
$idOption2 = GUICtrlCreateRadio("Option 2", 10, 40, 120, 20)
    GUICtrlSetOnEvent($idOption2,"_EnableStart")
$idStart = GuiCtrlCreateButton("Select Radio Above", 10, 70, 120, 50,bitor($BS_CENTER,0,0))
    GUICtrlSetOnEvent($idStart,"Startallrun")
    GUICtrlSetState($idStart, $GUI_DISABLE)

Func _EnableStart()
    GUICtrlSetState($idStart, $GUI_ENABLE)
EndFunc

Func Startallrun()
    If GUICtrlRead($idOption1) = $GUI_CHECKED Then
        MsgBox(4096, "Starting", "Running Option 1")
    ElseIf GUICtrlRead($idOption2) = $GUI_CHECKED Then
        MsgBox(4096, "Starting", "Running Option 2")
    EndIf
EndFunc

 

I have already resolved my problem using $GUI_DISABLE, but thanks for the help, I appreciate :)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By undcover
      Hello, I'm automating part of the note taking ability of my old bad POS, I managed to do much of the heavy lifting in the past weeks, I can finally do everything i want and more.
      Now I have a form with two buttons that expand the form to show a note taking beast that can lets us escape the hell of the one way editing the POS actually support (no cursor just delete. want to change the time on that order better delete everything and start the note from scratch, well not anymore)
      Now i'm stuck, my form shows up as two buttons over the POS window, however I need it to go away when I minimized the POS or switch to a different page or application, I was able to do so by doing a while loop, it worked badly as it will repeat the show command infinitely and if i break the loop then there's no way to restart the loop if the user didn't interact with the buttons directly.
      I have many ways I could know when controls are visible and it worked, I just don't have a way of constantly checking for this without straining the CPU, I know if I work it somehow I could do a while loop that can work, but it'll be CPU intensive. (Bad POS entails BAD PC)
      Should I make another form that does the loop? can I make the loop slower ?
      I'm using  VB.net VS 2017 with AutoitX dll.
      EDIT: Hello anyone who searched for this, if you're and idiot like me and forgot that Timers exist then this will jog your memory
       
      Add a timer to your form, set the timer for 1 sec intervals (dealers choice)
      start your timer (within form load or manually)
      Timer1.start()
      then double click the timer to create a Timer tick (for my case the control visibility test i want to make each second)
      it should look something like this :
          Private Sub timer1_Tick(sender As Object, e As EventArgs) Handles timer1.Tick         dim visibleform = ait.ControlCommand("my app", "", "[NAME:wacontact]", "IsVisible", "")         If visibleform = 0 Then             Me.Hide() ElseIf visibleform = 1 And Me.Visible = False Then ' to prevent the timer ticks from interupting any sendkeys or something we put two conditions. Me.Show() End If     End Sub remarks: ait. is the call I set for Autoit DLL.
       
       
       
    • By BlueSkyMemory
      Hello guys! I'm a rookie in AutoIt lol.
      I've tried to looking up in MSDN and the UDFs, but it can only get the GUID of a usual partition and with the GUID to control it. Now I have no waysūüė•.
      Thanks a lot for your help!
    • By Zaoka
      Hi guys,
      i have simple report in PowerPivot that shows Orders (Values) by Regions (Row) and Weeks (Columns). In Filter field is WeekDAYS (Monday,Tuesday,Wednesday,Thursday etc )
      how to filter WeekDAYS Filed on WEEKDAYYesterday with autoit ?
      my junky try
      #include <Date.au3> #include <Excel.au3> Local $sWEEKDAYYesterday = _DateDayOfWeek(@WDAY-1) Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\.......\Orders.xlsb") Sleep (5000) $oExcel.ActiveWorkbook.RefreshAll Sleep (5000) $oExcel.Application.Sheets("Sheet1").PivotTables("PivotTable1").PivotFields("WeekDAYS").PivotFilters($sWEEKDAYYesterday)  
      Error result
      $oExcel.Application.Sheets("PivotTable1").PivotTables("PivotTable1").PivotFields("WeekDAYS").PivotFilters($sWEEKDAYYesterday) $oExcel.Application^ ERROR  
    • By silber
      Probably something simple, but i'm trying to create a trigger that happens if the user is idle for too long (in this example 10 seconds).
      #include <Timers.au3> While 1 $CurrIdleTime = _Timer_GetIdleTime() Switch $CurrIdleTime Case $CurrIdleTime >= 10001 MsgBox(64,"Current Idle Time",$CurrIdleTime) Exit EndSwitch WEnd So if I run this and don't press anything the message box will trigger in 10 seconds, but if press anything the message box will immediately trigger.  The $CurrIdleTime given to me in the message box always reads 0 in the second scenario, so I'm not understanding why the case would trigger if it's clearly not greater than or equal to 10001.
      Does moving the mouse/pressing a key cause _Timer_GetIdleTime() to very quickly go to another value than zero?  I tried specifying Number($CurrIdleTime), but it didn't make any difference.
      Any insight would be appreciated, thank you.
    • By MightyWeird
      Hello,
       
      I am alwasy struggeling to do multiple things  at the same time.
      I have a main screen with a button which calls the function ninite1.
      The function "ninite1" then executes and fires a new gui.
      The program start to run with the gui (test) in the back ground
       
      Now I would like to have a counter (_count() which shows how long this program is running within this gui (ninitegui)
      Somebody?
       
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <ColorConstantS.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <InetConstants.au3> _ninite1() Func _ninite1() GLOBAL $count = 0 Local $NINITEGUI = GUICreate("Runtimes", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) Local $idLabel2 = GUICtrlCreateLabel("test", 600, 150, @DesktopWidth, 150) GLOBAL $lblData = GuICtrlCreateLabel("", 40, 40,50,50) _Count() Sleep(1000) GUISetState(@SW_SHOW, $NINITEGUI) Run(@ScriptDir & "\Resources" & "\Runtime\ninite.exe") ;Run(@ScriptDir & "\Resources" & "\Runtime\vlcetc.exe") While 1 If ControlCommand("Ninite", "Close", "[CLASS:Button; INSTANCE:1]", "IsEnabled", "") Then ControlClick("Ninite", "Close", 2) Sleep(15) ; Important or you eat all the CPU which will not help the defrag! ExitLoop EndIf WEnd GUIDelete($NINITEGUI) EndFunc ;==>_ninite1 Func _Count() For $i = $count To 100 GuiCtrlSetData($lblData, $i) Sleep(1000) Next EndFunc  
×
×
  • Create New...