Jump to content

How to use two loops


Recommended Posts

I'm want to use 2 loop to made 1 code auto close windows but the code know only 1 in 2 loop :) if loop 2 run all the button in loop 1 disabled :P

This is my code

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$shutting = GUICreate("Shutdown", 217, 89, 192, 124)
$shutdown = GUICtrlCreateButton("Shutdown Now", 8, 48, 99, 25)
$cancel = GUICtrlCreateButton("Canclel", 128, 48, 75, 25)
$report = GUICtrlCreateLabel("", 8, 16, 198, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    $i = 0
While $i <= 20
    $s = 20-$i
GUICtrlSetData ($report,"Windows will shutting down in " & $s & " second")
    $s = ""
    $i = $i+1
    Sleep(1000)
WEnd
msgbox (0,"Report", "Done.......")
exit
        If $nMsg = $cancel then Exit
    if $nMsg = $shutdown then
        msgbox (0,"Report", "Done.......")
exit
endif
if $nMsg = $GUI_EVENT_CLOSE then exit
WEnd

Thanks everyone had read my topic :)

Edited by anhchangtk
Link to comment
Share on other sites

  • Moderators

anhchangtk,

You actually need 3 loops: :)

1. Outer to keep looking for button presses.

2. Middle to keep your timer running.

3. Inner to wait for 1 sec between timer clicks AND keep looking for the Cancel button.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$shutting = GUICreate("Shutdown", 217, 89, 192, 124)
$shutdown = GUICtrlCreateButton("Shutdown Now", 8, 48, 99, 25)
$cancel = GUICtrlCreateButton("Cancel", 128, 48, 75, 25)
$report = GUICtrlCreateLabel("", 8, 16, 198, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Outer
    Switch GUIGetMsg()
        Case $shutdown
            $s = 20
            While 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Middle
                GUICtrlSetData($report, "Windows will shutting down in " & $s & " second")
                $iBegin = TimerInit()
                While TimerDiff($iBegin) < 1000 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Inner
                    If GUIGetMsg() = $cancel Then
                        GUICtrlSetData($report, "")
                        ExitLoop 2 ; <<<<<<<<<<< Because we have 2 loops to exit
                    EndIf ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Inner
                WEnd
                $s -= 1
                If $s = 0 Then
                    MsgBox(0, "Report", "Done.......")
                    Exit
                EndIf
            WEnd ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Middle
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Outer

Ask if anything is unclear.

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

 

Link to comment
Share on other sites

Maybe...

$iBegin = TimerInit()
While 1
    GUICtrlSetData($report, "Windows will shutting down in " & $s & " second")

    If GUIGetMsg() = $cancel Then
        GUICtrlSetData($report, "")
        ExitLoop
    EndIf

    If TimerDiff($iBegin) < 1000 Then
        $iBegin = TimerInit()
        $s -= 1
    EndIf

    If $s = 0 Then
        MsgBox(0, "Report", "Done.......", 3)
        Exit
    EndIf
WEnd

8)

NEWHeader1.png

Link to comment
Share on other sites

OK thanks Valuater and Melba23 :)

@Valuater: code you run very well but i want when code run the $report will start count down :) and when click button windows will immediately shutdown the $report not will count down :P

@Melba23: Your code me haven't used :idea:

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...