Sign in to follow this  
Followers 0
gcue

how to stop a loop

7 posts in this topic

hello.

i have a checkmark setting within the utility that initiates a loop

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $viewmonitoritem
            If BitAND(GUICtrlRead($viewmonitoritem), $GUI_UNCHECKED) = $GUI_UNCHECKED Then
                GUICtrlSetState($viewmonitoritem, $GUI_CHECKED)
               $loop="yes"
               Call("PingDevices")
            Else
                GUICtrlSetState($viewmonitoritem, $GUI_UNCHECKED)
               $loop="no" 
            EndIfoÝ÷ ÚØ^)²Ö«¶Ê'qëayÈ^rI®H¬±é^r×mçºÇ¨~Øb²§×¯Ç¬Ëayû§rبØZ¶Éh¢§«­¢+Ù%ÀÌØí±½½ÀôÅÕ½ÐíåÌÅÕ½ÐìQ¡¸(M±À ÔÀÀÀ¤(
±° ÅÕ½ÐíA¥¹Ù¥ÌÅÕ½Ðì¤(±Í(¹%

Share this post


Link to post
Share on other sites



ExitLoop

put that in the loop and when it hits that it will exit the loop

Share this post


Link to post
Share on other sites

i guess i dont have a true loop because that doesnt work.

i just set a condition and if the condition is met it will repeat keep calling the pingdevices function.

not sure how to get out of that.. maybe i have to do the loop differently?

Share this post


Link to post
Share on other sites

Make the While part look like this While $active

and then to stop the loop...type: $active = 0 or to start...type $active = 1

at the top of your script put...Global $active = 1

Share this post


Link to post
Share on other sites

hmm not sure what you mean.

Make the While part look like this While $active

and then to stop the loop...type: $active = 0 or to start...type $active = 1

at the top of your script put...Global $active = 1

Share this post


Link to post
Share on other sites

i guess i dont have a true loop because that doesnt work.

i just set a condition and if the condition is met it will repeat keep calling the pingdevices function.

not sure how to get out of that.. maybe i have to do the loop differently?

well, you are missing a WEnd at the end of the loop

Share this post


Link to post
Share on other sites

its there i just didnt copy the whole thing.. heres the whole script =)

#include <GuiConstants.au3>
#include <Constants.au3>
#include <file.au3>

Global $statuslabelitem[1000]

If Not FileExists("\" & @UserName) Then
    DirCreate(@UserName)
EndIf

$devicesfile = @UserName & "\devices.ini"

If Not FileExists(@UserName & "\devices.ini") Then
    FileWrite($devicesfile, "[CRGI Trading Room]" & @CRLF & _
            "LAO-53-TRADING4-HP4650DN=10.60.21.220" & @CRLF & _
            "" & @CRLF & _
            "[CWI Trading Room]" & @CRLF & _
            "LAO-34-E-CWI-TRADING3-HP4350DTN=10.60.10.223" & @CRLF & _
            "HP Digital Sender 9200C=10.60.10.224")
EndIf

$statusfile = @TempDir & "\status.csv"
$loop="no"

If FileExists(@TempDir & "\status.csv") Then
    FileDelete(@TempDir & "\status.csv")
EndIf

If FileExists(@UserName & "\status.csv") Then
    FileDelete(@UserName & "\status.csv")
EndIf

FileWrite($statusfile, "Location, Device, Status")

$parent = GUICreate("Device Pinger v0.1", 450, 250)

$filemenu = GUICtrlCreateMenu("&File")
$filepingitem = GUICtrlCreateMenuItem("Ping Devices", $filemenu)
$fileedititem = GUICtrlCreateMenuItem("Edit Device List", $filemenu)
$fileexportitem = GUICtrlCreateMenuItem("Export Status to CSV", $filemenu)
$fileexititem = GUICtrlCreateMenuItem("Exit", $filemenu)
$viewmenu = GUICtrlCreateMenu("&View", -1, 2)

$viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu)
GUICtrlSetState($viewstatusitem, $GUI_CHECKED)

$viewmonitoritem = GUICtrlCreateMenuItem("Monitor", $viewmenu)
GUICtrlSetState($viewmonitoritem, $GUI_UNCHECKED)


$helpmenu = GUICtrlCreateMenu("&Help")
$helpitem = GUICtrlCreateMenuItem("About", $helpmenu)
$statuslabel = GUICtrlCreateListView("Location|Device|Status",0,0,450,230)
For $i = 0 to 999 step 1
    $statuslabelitem[$i] = GUICtrlCreateListViewItem(" | | ",$statuslabel)
Next

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $viewstatusitem
            If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED)
                GUICtrlSetState($statuslabel, $GUI_HIDE)
            Else
                GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
                GUICtrlSetState($statuslabel, $GUI_SHOW)
            EndIf
            
        
        Case $msg = $viewmonitoritem
            If BitAND(GUICtrlRead($viewmonitoritem), $GUI_UNCHECKED) = $GUI_UNCHECKED Then
                GUICtrlSetState($viewmonitoritem, $GUI_CHECKED)
               $loop="yes"
               Call("PingDevices")
            Else
                GUICtrlSetState($viewmonitoritem, $GUI_UNCHECKED)
               $loop="no"
               ExitLoop
            EndIf
        
            
        Case $msg = $filepingitem
            PingDevices()
        Case $msg = $fileedititem
            EditCSV()
        Case $msg = $fileexportitem
            ExportCSV()
        Case $msg = $fileexititem
            Xbutton()
        Case $msg = $helpitem
            About()
        Case $msg = $GUI_EVENT_CLOSE 
            Xbutton()
    EndSelect
WEnd



Func PingDevices()
  
    For $i = 0 to 999
        GUICtrlSetData($statuslabelitem[$i]," | | ")
    Next

    If FileExists(@TempDir & "\status.csv") Then
        FileDelete(@TempDir & "\status.csv")
        FileWrite($statusfile, "Location, Device, Status")
    EndIf


    Local $location, $L, $device, $d, $i=0
    $location = IniReadSectionNames(@UserName & "\devices.ini")
    If IsArray($location) Then
        For $L = 1 To $location[0]
            $device = IniReadSection(@UserName & "\devices.ini", $location[$L])
            If IsArray($device) Then
                For $d = 1 To $device[0][0]

                    Ping($device[$d][1])

                    If @error Then
                        $status = "OFFLINE"
                    EndIf

                    If Not @error Then
                        $status = "ONLINE"
                    EndIf
                    GUICtrlSetData($statuslabelitem[$i],$location[$L] & "|" & $device[$d][0] & "|" & $status) 
                    FileWrite($statusfile, '' & @CRLF & _
                            $location[$L] & "," & $device[$d][0] & "," & $status)
                    $i = $i + 1
                Next
            Else
                MsgBox(16, "Error", "There was an error reading section: " & $location[$L] & @CRLF & "Section Number was: " & $L)
            EndIf
        Next
    Else
        MsgBox(16, "", "Error occurred, probably no INI file.")
    EndIf
    
    If $loop="yes" Then
        Sleep(5000)
        Call("PingDevices")
    Else
        EndIf
    
EndFunc   ;==>PingDevices


Func EditCSV()
    ShellExecute(@UserName & "\devices.ini")
EndFunc   ;==>EditCSV

Func ExportCSV()
    $csvfile = FileSaveDialog("Export CSV", @UserProfileDir & "\Desktop", "Comma Seperated Values (*.csv)", 16)
    FileCopy(@TempDir & "\status.csv", $csvfile & ".csv", 1)
    ShellExecute($csvfile & ".csv")
EndFunc   ;==>ExportCSV

Func About()
    MsgBox(262208, "About", 'Device Pinger v0.1' & @CRLF & _
            '' & @CRLF & _
            'Pings devices in: ' & @UserName & '\devices.ini' & @CRLF & _
            '(You can add as many locations/devices as you want.)' & @CRLF & _
            '' & @CRLF & _
            'Contact GXM x90760 for questions/suggestions.')
EndFunc   ;==>About


Func Xbutton()
    FileDelete(@TempDir & "\status.csv")
    Exit
EndFunc   ;==>Xbutton

well, you are missing a WEnd at the end of the loop

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