Jump to content

Loop not working.....


dwell
 Share

Recommended Posts

Hi all....

Thanks in advance for reading my post! The problem is I have some code running a loop statement and it only seems to work correctly the first time through. Here is the code:

#include <Process.au3>
$WinTitle = 'Untitled - Notepad'
$num = 0

While 1

    If WinExists( $WinTitle ) And $num = 0 Then
        $rc = _RunDos("c:\blah -a 10.1.10.30 -c XNET  -k blahblah -l 88.43.102.76:3882")
        $num = 1
        MsgBox(0, "", "yes")
    Else
        If WinWaitClose("Untitled") = 1 And $num = 1 Then
            $PID = ProcessExists("blah.exe")
            If $PID Then ProcessClose($PID)
            $num = 0
            MsgBox(0, "", "no")
        EndIf
    EndIf

WEnd

The reason I am using the $num is to eliminate processor load as the CPU creeps way up without it. When I run the script for the first time I get the MsgBox(s) and all as expected. The second time through it seems to only run the first part of the loop but does not fire the WinWaitClose. Am I missing something here?

Thanks,

dwell

Link to comment
Share on other sites

Hi all....

Thanks in advance for reading my post! The problem is I have some code running a loop statement and it only seems to work correctly the first time through. Here is the code:

#include <Process.au3>
$WinTitle = 'Untitled - Notepad'
$num = 0

While 1

    If WinExists( $WinTitle ) And $num = 0 Then
        $rc = _RunDos("c:\blah -a 10.1.10.30 -c XNET  -k blahblah -l 88.43.102.76:3882")
        $num = 1
        MsgBox(0, "", "yes")
    Else
        If WinWaitClose("Untitled") = 1 And $num = 1 Then
            $PID = ProcessExists("blah.exe")
            If $PID Then ProcessClose($PID)
            $num = 0
            MsgBox(0, "", "no")
        EndIf
    EndIf

WEnd

The reason I am using the $num is to eliminate processor load as the CPU creeps way up without it. When I run the script for the first time I get the MsgBox(s) and all as expected. The second time through it seems to only run the first part of the loop but does not fire the WinWaitClose. Am I missing something here?

Thanks,

dwell

I wish I could see the issue, but I don't.

Don't you wish creating loops in autoit was as easy as it is in C++?

Link to comment
Share on other sites

Hey guys.....thanks for the responses!

Just to clarify....what I am really trying to accomplish with this is basically triggering a program to run off of the status of the Notepad window. If it is open then run BLAH.....and when it closes kill BLAH. It works the first time I open and close Notepad....after that the loop gets moody.

Thanks,

dwell

Link to comment
Share on other sites

  • Moderators

dwell,

Try splitting the 2 elements of the If statement:

#include <Process.au3>
$WinTitle = 'Untitled - Notepad'
$num = 0

While 1

    If WinExists( $WinTitle ) Then
        If $num = 0 Then
            $rc = _RunDos("c:\blah -a 10.1.10.30 -c XNET  -k blahblah -l 88.43.102.76:3882")
            $num = 1
            MsgBox(0, "", "yes")
        EndIf
    Else
        If $num = 1 Then
            $PID = ProcessExists("blah.exe")
            If ProcessExists("blah.exe") Then ProcessClose($PID)
            $num = 0
            MsgBox(0, "", "no")
        EndIf
    EndIf

WEnd

It works for me! ;)

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

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