Sign in to follow this  
Followers 0
Jester009

Loop problem

13 posts in this topic

Hi,

How can I wait for user input through a GUI inside a FOR loop? What I want to do is repeat a certain action few times while getting input from the user... Any help would be greatly appreciated.

Thanks

Jester009

Share this post


Link to post
Share on other sites



Hi,

How can I wait for user input through a GUI inside a FOR loop? What I want to do is repeat a certain action few times while getting input from the user... Any help would be greatly appreciated.

Thanks

Jester009

K I think I know what you mean

What this does is does a For loop 5000 times and moves a progress bar the whole time while reading user input

#include <GUIConstants.au3>

$Progress = 1

$AForm1 = GUICreate("AForm1", 162, 114, 204, 146)
$Input1 = GUICtrlCreateInput("Enter Input Here", 38, 4, 121, 21)
$Label1 = GUICtrlCreateLabel("Input:", 4, 6, 31, 17)
$Label2 = GUICtrlCreateLabel("Users Input", 38, 28, 58, 17)
$Progress1 = GUICtrlCreateProgress(4, 48, 155, 21)
;GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$Label3 = GUICtrlCreateLabel("Notice the loading bar move", 4, 72, 149, 17)
$Label4 = GUICtrlCreateLabel("while input is reviced and read", 4, 92, 147, 17)
GUISetState()

For $Loop = 1 to 5000
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    $UsersInput = GUICtrlRead($Input1)
    GUICtrlSetData($Label2, $UsersInput)
    $Progress += 1
    GUICtrlSetData($Progress1, $Progress)
    If $Progress > 155 Then
        $Progress = 1
    EndIf
Next

Share this post


Link to post
Share on other sites

Thanks a lot for the reply frostfel

In the code you provided it does not wait till the user enters the value, I mean it will exit itself if the user does nor enter anything. This is what I want...

In the GUI there will be a textfield (input) and a button. When the user enters his name and press the button it will be written to a  text file. I want to do this for five times (User will be prompted five times)

I can hadle the GUI and the file write part but not the looping part. Tried several times. Any help??

Thanks

Share this post


Link to post
Share on other sites

post some code

and try a While loop or Do Until loop if you don't absolutely need to use a For loop

Share this post


Link to post
Share on other sites

Tried several times I can't get it :)

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 306, 159, 189, 123)
$Input1 = GUICtrlCreateInput("", 48, 80, 105, 21)
$Button1 = GUICtrlCreateButton("Start", 184, 32, 65, 25, 0)
$Button2 = GUICtrlCreateButton("OK", 184, 80, 65, 25, 0)
$Input2 = GUICtrlCreateInput("", 48, 40, 105, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $Button1 Then
        For $i = 1 To GUICtrlRead($Input2)
            If $nMsg = $Button2 Then
                MsgBox(0, "Name", GUICtrlRead($Input1))
            EndIf
            If $nMsg = $GUI_EVENT_CLOSE Then
                Exit
            EndIf
        Next
    EndIf
WEnd

Share this post


Link to post
Share on other sites

I think I see your problem. You said To GUICtrlRead($Input2), that means loop as many times as $Input2 has, so if that's the value of how many times you want to write it's fine but if not you need to set it to static, like To 5.

Share this post


Link to post
Share on other sites

Yea I want the user to define how many times he want to enter the name.

I can't figure out why the script does not care about the second IF statement...

:)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Instead of using if statements use case statements, they would probably work better for you.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 306, 159, 189, 123)
$Input1 = GUICtrlCreateInput("", 48, 80, 105, 21)
$Button1 = GUICtrlCreateButton("Start", 184, 32, 65, 25, 0)
$Button2 = GUICtrlCreateButton("OK", 184, 80, 65, 25, 0)
$Input2 = GUICtrlCreateInput("", 48, 40, 105, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch = $nMsg
    Case $Button1 Then
        For $i = 1 To GUICtrlRead($Input2)
     Case $Button2 Then
                MsgBox(0, "Name", GUICtrlRead($Input1))
      Case $GUI_EVENT_CLOSE Then
                Exit
        Next
    EndIf
EndSwitch
WEnd
Edited by dbzfanatic

Share this post


Link to post
Share on other sites

Tried SWITCH and SELECT, with no success :)

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 306, 159, 189, 123)
$Input1 = GUICtrlCreateInput("", 48, 80, 105, 21)
$Button1 = GUICtrlCreateButton("Start", 184, 32, 65, 25, 0)
$Button2 = GUICtrlCreateButton("OK", 184, 80, 65, 25, 0)
$Input2 = GUICtrlCreateInput("", 48, 40, 105, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Select
    Case $nMsg = $Button1
        MsgBox(0, "Name", "Button1 pressed")
        For $i = 1 To GUICtrlRead($Input2)
            Select
            Case $nMsg = $Button2
                MsgBox(0, "Name", GUICtrlRead($Input1))
            Case $nMsg = $GUI_EVENT_CLOSE
                Exit
            EndSelect
        Next
    EndSelect
WEnd

Share this post


Link to post
Share on other sites

Try this, I didn't test the other code, this I tested.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 306, 159, 189, 123)
$Input1 = GUICtrlCreateInput("", 48, 80, 105, 21)
$Button1 = GUICtrlCreateButton("Start", 184, 32, 65, 25, 0)
$Button2 = GUICtrlCreateButton("OK", 184, 80, 65, 25, 0)
$Input2 = GUICtrlCreateInput("", 48, 40, 105, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button1
        $var2 = GUICtrlRead($Input2)
    Case $Button2
        For $i = 1 To $var2
            MsgBox(0, "Name", GUICtrlRead($Input1))
        Next
    Case $GUI_EVENT_CLOSE
        Exit
EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Thanks dbzfanatic. That seem to be better...

But still it does not prompt for wait till the user enters the name in the field. I mean it displays the same value entered in the begining for five times...

May be clearing the input may help??

Share this post


Link to post
Share on other sites

I thought you said you could take care of that. I'm teasing. To do that instead of Using a message box just use an InputBox.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 306, 159, 189, 123)
$Input1 = GUICtrlCreateInput("", 48, 80, 105, 21)
$Button1 = GUICtrlCreateButton("Start", 184, 32, 65, 25, 0)
$Button2 = GUICtrlCreateButton("OK", 184, 80, 65, 25, 0)
$Input2 = GUICtrlCreateInput("", 48, 40, 105, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button1
        $var2 = GUICtrlRead($Input2)
    Case $Button2
        For $i = 1 To $var2
                If $i = 1 Then
            MsgBox(0, "Name", GUICtrlRead($Input1))
                Else
                        *some variable here to store the new value* = InputBox("Input new value.", "Please input a new value.")
                EndIf
        Next
    Case $GUI_EVENT_CLOSE
        Exit
EndSwitch
WEnd

Once again this code is untested so it may or may not work the way you want but it'll point you in the right direction I hope.

Share this post


Link to post
Share on other sites

I manged to do it with an input box. I tried to use the GUI coz it's more neat (do not want a window poping up everytime)

I have been stuck here for two days now. Is it I'm just a newbie or can't this be achieved with Autoit??

Anyways thanks for helping dbzfanatic

:)

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