Jester009 Posted September 22, 2007 Share Posted September 22, 2007 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 Link to comment Share on other sites More sharing options...
frostfel Posted September 22, 2007 Share Posted September 22, 2007 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.ThanksJester009K I think I know what you meanWhat 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 Link to comment Share on other sites More sharing options...
Jester009 Posted September 22, 2007 Author Share Posted September 22, 2007 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 Link to comment Share on other sites More sharing options...
narayanjr Posted September 22, 2007 Share Posted September 22, 2007 post some code and try a While loop or Do Until loop if you don't absolutely need to use a For loop Link to comment Share on other sites More sharing options...
Jester009 Posted September 22, 2007 Author Share Posted September 22, 2007 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 Link to comment Share on other sites More sharing options...
dbzfanatic Posted September 22, 2007 Share Posted September 22, 2007 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. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
Jester009 Posted September 22, 2007 Author Share Posted September 22, 2007 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... Link to comment Share on other sites More sharing options...
dbzfanatic Posted September 22, 2007 Share Posted September 22, 2007 (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 September 22, 2007 by dbzfanatic Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
Jester009 Posted September 22, 2007 Author Share Posted September 22, 2007 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 Link to comment Share on other sites More sharing options...
dbzfanatic Posted September 22, 2007 Share Posted September 22, 2007 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 Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
Jester009 Posted September 22, 2007 Author Share Posted September 22, 2007 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?? Link to comment Share on other sites More sharing options...
dbzfanatic Posted September 22, 2007 Share Posted September 22, 2007 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. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
Jester009 Posted September 22, 2007 Author Share Posted September 22, 2007 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now