Sign in to follow this  
Followers 0
bwsfca

Simple Loop Help

6 posts in this topic

Could someone tell me why my exit button will not work? It seems to only work when there is no Sleep within the While statement. Is there any other way to pause within the while statement? In the end, I would like this script to monitor the text in 3 specific controls, from 3 applications, displaying them in the list below.

CODE
#include <GuiConstants.au3>

; Create the GUI.

GuiCreate("Pas Check", 400, 400)

; Creates a BUTTON Control.

$BrkEnd = GUICtrlCreateButton("Exit", 90, 90, 80, 25)

; set the GUI as visible.

GuiSetState()

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Or $msg = $BrkEnd Then

Exit

EndIf

$P1 = ControlGetText("AutoIt Help", "", "Edit1")

$P2 = ControlGetText("AutoIt Help", "", "Edit1")

$P3 = ControlGetText("AutoIt Help", "", "Edit1")

$listView = GuiCtrlCreateListView("Process|Status|", 110, 190, 110, 80)

GuiCtrlCreateListViewItem("PAS1|" & $P1, $listView) ; sets the list view items.

GuiCtrlCreateListViewItem("PAS2|" & $P2, $listView)

GuiCtrlCreateListViewItem("PAS3|" & $P3, $listView)

sleep (1000)

WEnd

Share this post


Link to post
Share on other sites



sleep(1000) will make the button not work correctly...

#include <GuiConstants.au3>
; Create the GUI.
GUICreate("Pas Check", 400, 400)
; Create the listview
$listView = GUICtrlCreateListView("Process|Status|", 110, 190, 110, 80)
; Creates a BUTTON Control.
$BrkEnd = GUICtrlCreateButton("Exit", 90, 90, 80, 25)
; set the GUI as visible.
GUISetState()
; start a timer
$begin = TimerInit()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $BrkEnd Then
        Exit
    EndIf
    If TimerDiff($begin) >= 1000 Then ; wait time
        $begin = TimerInit()
        $P1 = ControlGetText("AutoIt Help", "", "Edit1")
        $P2 = ControlGetText("AutoIt Help", "", "Edit1")
        $P3 = ControlGetText("AutoIt Help", "", "Edit1")
        GUICtrlCreateListViewItem("PAS1|" & $P1, $listView) ; sets the list view items.
        GUICtrlCreateListViewItem("PAS2|" & $P2, $listView)
        GUICtrlCreateListViewItem("PAS3|" & $P3, $listView)
    EndIf
WEnd

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks, I need another option though.

With your code it is creating a list of values (each poll gets added to the list). In my previous code, it is updating the list (only ever 3 lines in the list); this is what I need. Does that make sense at all?

Share this post


Link to post
Share on other sites

Maybe.....

#include <GuiConstants.au3>
; Create the GUI.
GUICreate("Pas Check", 400, 400)
; Create the listview
$listView = GUICtrlCreateListView("Process|Status|", 110, 190, 110, 90)
        $item1 = GUICtrlCreateListViewItem("", $listView) 
        $item2 = GUICtrlCreateListViewItem("", $listView)
        $item3 = GUICtrlCreateListViewItem("", $listView)
; Creates a BUTTON Control.
$BrkEnd = GUICtrlCreateButton("Exit", 90, 90, 80, 25)
; set the GUI as visible.
GUISetState()
; start a timer
$begin = TimerInit()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $BrkEnd Then
        Exit
    EndIf
    If TimerDiff($begin) >= 1000 Then ; wait time
        $begin = TimerInit()
        $P1 = ControlGetText("AutoIt Help", "", "Edit1")
        $P2 = ControlGetText("AutoIt Help", "", "Edit1")
        $P3 = ControlGetText("AutoIt Help", "", "Edit1")
        GUICtrlSetData($item1, "PAS1|" & $P1)
        GUICtrlSetData($item2, "PAS2|" & $P2)
        GUICtrlSetData($item3, "PAS3|" & $P3)
    EndIf
WEnd

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Excellent thank you.

Share this post


Link to post
Share on other sites

Excellent thank you.

Welcome!

8)


NEWHeader1.png

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  
Followers 0