Jump to content
Sign in to follow this  
autoitquestion

infinite loop

Recommended Posts

autoitquestion

Hi,

I have program doing something like that:

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Local $msg, $scan_1, $scan_2, $btn, $res_1, $res_2

GUICreate("Trial",300,300)

GUISetState(@SW_SHOW)

GUICtrlCreateLabel("Enter 1st input:", 30, 50, 120)

GUICtrlCreateLabel("Enter 2nd input:", 30, 120, 120)

$scan_1 = GUICtrlCreateInput("", 150, 50, 100, 20)

GUICtrlSetState(-1, $GUI_DROPACCEPTED)

$scan_2 = GUICtrlCreateInput("", 150, 120, 100, 20)

$btn = GUICtrlCreateButton("Run", 120, 200, 60, 20)

GUISetState()

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $btn

$res_1=GUICtrlRead($scan_1)

$res_2=GUICtrlRead($scan_2)

Run("C:\Program Files\prog.exe")

WinActivate("[CLASS:WindowsForms10.window.8.app.0.37873b]", "")

Sleep(1000)

Send($res_1)

Send($res_2)

Send("{ENTER}")

GUIDelete()

EndSelect

WEnd

The problem is that if there is any problem after line code: Case $msg = $btn, so it cause infinite loop, and it won't exit program.

What should I do?

Pls help...

Noa

Edited by autoitquestion

Share this post


Link to post
Share on other sites
autoitquestion

Wrote above-I edited message

Thx :-)

Share this post


Link to post
Share on other sites
smartee

try this

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Local $msg, $scan_1, $scan_2, $btn, $res_1, $res_2

GUICreate("Trial", 300, 300)
GUICtrlCreateLabel("Enter 1st input:", 30, 50, 120)
GUICtrlCreateLabel("Enter 2nd input:", 30, 120, 120)
$scan_1 = GUICtrlCreateInput("", 150, 50, 100, 20)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$scan_2 = GUICtrlCreateInput("", 150, 120, 100, 20)
$btn = GUICtrlCreateButton("Run", 120, 200, 60, 20)
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            $res_1 = GUICtrlRead($scan_1)
            $res_2 = GUICtrlRead($scan_2)
            Run("C:\Program Files\prog.exe")
            WinActivate("[CLASS:WindowsForms10.window.8.app.0.37873b]", "")
            WinWaitActive("[CLASS:WindowsForms10.window.8.app.0.37873b]", "")
            Send($res_1)
            Send($res_2)
            Send("{ENTER}")
            GUIDelete()
            Exit
    EndSelect
WEnd

Share this post


Link to post
Share on other sites
autoitquestion

Thanks-what should I do if in if loop condition does take place and I wish that GUI will not exit or delete

For more details see code:

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Local $msg, $scan_1, $scan_2, $btn, $res_1, $res_2, $result, $flag, $file_1

GUICreate("MyProg",300,300)

GUISetState(@SW_SHOW)

GUICtrlCreateLabel("Enter 1st input:", 30, 50, 120)

GUICtrlCreateLabel("Enter 2nd input:", 30, 120, 120)

$scan_1 = GUICtrlCreateInput("", 150, 50, 100, 20)

GUICtrlSetState(-1, $GUI_DROPACCEPTED)

$scan_2 = GUICtrlCreateInput("", 150, 120, 100, 20)

$btn = GUICtrlCreateButton("Fix It!", 120, 200, 60, 20)

GUISetState()

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $btn

$res_1=GUICtrlRead($lot)

$res_2=GUICtrlRead($lc)

$file_1=FileExists("C:\temp\myTxt.txt")

If $file_1==0 Then

MsgBox(4096,"file not exist", "no file found")

$flag=1

ExitLoop

EndIf

Run("C:\temp\myProg.exe")

$result=MsgBox(4096, "Result", "Finish")

If $result==1 Then GUIDelete()

ExitLoop

EndSelect

WEnd

if code line does take place: If $file_1==0 Then ,means, $file_1=0, means, file not exist, I wish that it won't continue in program, but will stay the GUI, means, will not delete it.

What should I do?

Thanks!

Noa

Edited by autoitquestion

Share this post


Link to post
Share on other sites
autoitquestion

Anyone know the answer?

pls help me..

Share this post


Link to post
Share on other sites
autoitquestion

I edited my question appear 2 messages above

Share this post


Link to post
Share on other sites
autoitquestion

Okay. and can you pls help me with my problem?

Share this post


Link to post
Share on other sites
Jos

Okay. and can you pls help me with my problem?

Posting something that shows the problem and can be ran will probably help.

Reading your last question leaves a lot to guess and the posted script is full of errors.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
andrei0x309

Okay. and can you pls help me with my problem?

First do not use == for comparing things , in basic like syntax = is used for comparing instead of == , also mostly in basic like syntax == is the equivalent to === in c like syntax .

Secondly if you want a infinite loop you must use a infinite loop condition like

while 1 
; code here
wend

Cause if you use a condition that at some point will be equal to 0 then you can not have a infinite loop .

Share this post


Link to post
Share on other sites
smartee

what about

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Local $msg, $scan_1, $scan_2, $btn, $res_1, $res_2, $result, $flag, $file_1

GUICreate("MyProg", 300, 300)
GUISetState(@SW_SHOW)
GUICtrlCreateLabel("Enter 1st input:", 30, 50, 120)
GUICtrlCreateLabel("Enter 2nd input:", 30, 120, 120)
$scan_1 = GUICtrlCreateInput("", 150, 50, 100, 20)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$scan_2 = GUICtrlCreateInput("", 150, 120, 100, 20)
$btn = GUICtrlCreateButton("Fix It!", 120, 200, 60, 20)
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            $res_1 = GUICtrlRead($scan_1)
            $res_2 = GUICtrlRead($scan_2)
            $file_1 = FileExists("C:\temp\myTxt.txt")
            If $file_1 == 0 Then
                MsgBox(4096, "file not exist", "no file found")
                $flag = 1
            Else
                Run("C:\temp\myProg.exe")
                $result = MsgBox(4096, "Result", "Finish")
                If $result == 1 Then GUIDelete()
                ExitLoop
            EndIf
    EndSelect
WEnd

Share this post


Link to post
Share on other sites
autoitquestion

Thanks all for your help!!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.