Jump to content

Need help with looping or interupt


8879899714
 Share

Recommended Posts

hi guys, need some help here ... ok, i am trying to write a scipt whereby i have a GUI to control my options. so when i pressed the "start" button, it would count to 10 and then recount from 0 till i hit the "stop" button. after the "stop" button is pressed, it would wait for other key input.

the problem with my program below is that it during the counting, i cannot stop the count. so i was wondering could anyone add in a interupt for me? or enlighten me with some kinda of looping?

thanks in advance

#include <GUIConstants.au3>

Global $start

Global $way1x, $way1y, $kills

$showGUI = 0 ; setting the GUI condition

HotKeySet("{F6}", "show") ; using hotkey to show menu

Read()

GUICreate("Testscript", 300, 420)

$runbutton=GUICtrlCreateButton("Run", 0, 390, 80, 30) ; show the Run button

$stopbutton=GUICtrlCreateButton("Stop", 80, 390, 80, 30) ; show the Stop button

$savebutton = GUICtrlCreateButton("Save", 160, 390, 60, 30) ; show the Save button

$exitbutton = GUICtrlCreateButton("Exit", 220, 390, 80, 30) ; show the Exit button

GUICtrlCreateTab(0, 0, 300, 390)

$tab2 = GUICtrlCreateTabItem("WayPoints")

GUICtrlCreateLabel("Training Ground Location", 10, 30, 200, 20)

$checkCN = GUICtrlCreateCheckbox("", 20, 50, 20, 20) ; 1st checkbox location

GUICtrlCreateLabel("X : ", 60, 50, 15, 20)

;~ $way1x = Int(IniRead(".\testscript.ini","Waypoints","1x","-1"))

$input_x = GUICtrlCreateInput($way1x, 80, 50, 50, 20)

GUICtrlCreateLabel("Y : ", 150, 50, 15, 20)

;~ $way1y = Int(IniRead(".\testscript.ini","Waypoints","1y","-1"))

$input_y = GUICtrlCreateInput($way1y, 170, 50, 50, 20)

GUISetState(@SW_HIDE)

Func show()

If $showGUI = 0 Then

Read()

GUISetState(@SW_SHOW) ; show the menu when hotkey pressed

$showGUI = 1

Else

GUISetState(@SW_HIDE) ; hide the menu when hotkey pressed

$showGUI = 0

EndIf

EndFunc ;==>show

While 1 ; main body of program, loop till condition met

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE ; when the top right cancel button is pressed

Exit

Case $msg = $runbutton

$start = 1

ToolTip("Run Button Pressed")

Sleep(2000)

$kills = 0

ExitLoop

Case $msg = $savebutton ; pressing the Save button

Write()

MsgBox(64, "Test Box", "You clicked on Save!")

Case $msg = $exitbutton ; pressing the Exit button

Exit

EndSelect

WEnd

While 1

$msg = GUIGetMsg()

Select

Case $start = 1

If $msg = $stopbutton Then

$start = 0

ToolTip("Stopping")

$kills = 0

ExitLoop

Else

While $kills < 10

ToolTip("Count : " & $kills)

$kills = $kills + 1

Sleep(2000)

WEnd

EndIf

Case $start = 2

MsgBox(64, "Test Box", "Running Pixel Check!")

Sleep(2000)

ExitLoop

EndSelect

WEnd

WEnd

;;-------------------------------------- Functions --------------------------------

Func Write()

IniWrite(".\testscript.ini", "Waypoints", "1x", GUICtrlRead($input_x))

IniWrite(".\testscript.ini", "Waypoints", "1y", GUICtrlRead($input_y))

EndFunc ;==>Write

Func Read()

$way1x = Int(IniRead(".\testscript.ini", "Waypoints", "1x", "-1"))

$way1y = Int(IniRead(".\testscript.ini", "Waypoints", "1y", "-1"))

EndFunc ;==>Read

Link to comment
Share on other sites

Look at this my example and learn from it :)

#include <GUIConstants.au3>

GUICreate("Test",220,100) ;, -1,-1, $WS_CAPTION, $WS_EX_TOPMOST)
$progressbar = GUICtrlCreateProgress (10,15,200,20,$PBS_SMOOTH)
$procent = GUICtrlCreateLabel ('0 %', 10,40,200,20,$SS_CENTER)
$start = GUICtrlCreateButton ("Start",35,68,70,22)
$stop = GUICtrlCreateButton ("Stop",115,68,70,22)
GUICtrlSetState($stop,$GUI_DISABLE)
GUISetState()

$run = 0
$i = 0

While 1
  $msg = GUIGetMsg()

  If $msg = $GUI_EVENT_CLOSE Then ExitLoop
  If $msg = $start Then 
    $run = 1 
    GUICtrlSetState($start,$GUI_DISABLE)
    GUICtrlSetState($stop,$GUI_ENABLE)
  EndIf
  If $msg = $stop Then 
    $run = 0
    GUICtrlSetState($start,$GUI_ENABLE)
    GUICtrlSetState($stop,$GUI_DISABLE)
  EndIf
    If $run Then
    $i = $i + 1
    If $i > 100 Then $i = 0

    GUICtrlSetData ($progressbar,$i)
    GUICtrlSetData ($procent,$i & ' %')
    Sleep(100)
  EndIf
Wend
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...