grakker Posted April 2, 2005 Share Posted April 2, 2005 OK, I've been away from AutoIt3 for several months (Away from Windows in general, yeah!) and I'm rusty. I use a bash script to create a series of flash cards for use in class. I wanted to create a little AutoIt3 script to do the same thing that I could use on the computers at work, and give to a couple of my fellow teachers. Anyway, the script should open a Window with three input panes. They are ANSWER, QUESTION, and ANSWER. The top answer is the answer to the last question asked, just for reference. It defaults to the first card. For some reason, the following script is reading $Question and $TempAnswer, but not $Answer. Please someone tell me what an idiot I am. By the way, this is using Abiword, just change the "Abi" to "Word" and it should work the same. Thanks. expandcollapse popup#include <GUIConstants.au3> Opt ("WinTitleMatchMode", 2) Global $Answer = " " Global $Question = " " Global $TempAnswer = "I have the first card." While 1 EnterAQ($TempAnswer) Looping() WEnd Func EnterAQ($Answer) GUICreate('Type "END" in ANSWER to exit', 320, 240, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES GUICtrlCreateLabel("Answer:", 10, 5) $Answer_C = GUICtrlCreateInput($TempAnswer, 10, 25, 300, 40) GUICtrlCreateLabel("Question:", 10, 70) $Question_C = GUICtrlCreateInput("", 10, 90, 300, 40) GUICtrlCreateLabel("Answer:", 10, 135) $TempAnswer_C = GUICtrlCreateInput("", 10, 150, 300, 40) $btn = GUICtrlCreateButton("Ok", 10, 200, 60, 20) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btn $Question = GUICtrlRead($Question_C) $Answer = GUICtrlRead($Answer_C) $TempAnswer = GUICtrlRead($TempAnswer_C) GUIDelete() ExitLoop EndSelect WEnd If $Answer = 'END' Then Exit EndIf EndFunc ;==>EnterAQ Func Looping() WinActivate("Abi") WinWaitActive("Abi") Send($Answer) Send("Answer: {ENTER}" & $Answer & "{ENTER 2}" & "Question: {ENTER}" & $Question & "!i{ENTER}") WinWaitActive("Insert") Send("{ENTER}") EndFunc ;==>Looping I know the code is ugly, as mine usually is. If anyone wants to point out my style gaffs, feel free I won't be offended. Link to comment Share on other sites More sharing options...
quaizywabbit Posted April 2, 2005 Share Posted April 2, 2005 (edited) OK, I've been away from AutoIt3 for several months (Away from Windows in general, yeah!) and I'm rusty. I use a bash script to create a series of flash cards for use in class. I wanted to create a little AutoIt3 script to do the same thing that I could use on the computers at work, and give to a couple of my fellow teachers.Anyway, the script should open a Window with three input panes. They are ANSWER, QUESTION, and ANSWER. The top answer is the answer to the last question asked, just for reference. It defaults to the first card.For some reason, the following script is reading $Question and $TempAnswer, but not $Answer. Please someone tell me what an idiot I am.By the way, this is using Abiword, just change the "Abi" to "Word" and it should work the same. Thanks.#include <GUIConstants.au3>Opt ("WinTitleMatchMode", 2)Global $Answer = " "Global $Question = " "Global $TempAnswer = "I have the first card."While 1 EnterAQ($TempAnswer) Looping()WEndFunc EnterAQ($Answer) GUICreate('Type "END" in ANSWER to exit', 320, 240, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES GUICtrlCreateLabel("Answer:", 10, 5) $Answer_C = GUICtrlCreateInput($TempAnswer, 10, 25, 300, 40) GUICtrlCreateLabel("Question:", 10, 70) $Question_C = GUICtrlCreateInput("", 10, 90, 300, 40) GUICtrlCreateLabel("Answer:", 10, 135) $TempAnswer_C = GUICtrlCreateInput("", 10, 150, 300, 40) $btn = GUICtrlCreateButton("Ok", 10, 200, 60, 20) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btn $Question = GUICtrlRead($Question_C) $Answer = GUICtrlRead($Answer_C) $TempAnswer = GUICtrlRead($TempAnswer_C) GUIDelete() ExitLoop EndSelect WEnd If $Answer = 'END' Then Exit EndIf Return $answerEndFunc ;==>EnterAQFunc Looping() WinActivate("Abi") WinWaitActive("Abi") Send($Answer) Send("Answer: {ENTER}" & $Answer & "{ENTER 2}" & "Question: {ENTER}" & $Question & "!i{ENTER}") WinWaitActive("Insert") Send("{ENTER}") EndFunc ;==>LoopingI know the code is ugly, as mine usually is. If anyone wants to point out my style gaffs, feel free I won't be offended.<{POST_SNAPBACK}>not sure...but I think the func needs to "return" the value of $answer Edited April 2, 2005 by quaizywabbit [u]Do more with pre-existing apps![/u]ANYGUIv2.8 Link to comment Share on other sites More sharing options...
grakker Posted April 2, 2005 Author Share Posted April 2, 2005 not sure...but I think the func needs to "return" the value of $answer<{POST_SNAPBACK}>Thanks, but no. $Answer is a global, so that doesn't matter, I believe. Aside from that, my other two variables which are initialized and read in the same blocks are coming out fine. Link to comment Share on other sites More sharing options...
phillip123adams Posted April 2, 2005 Share Posted April 2, 2005 For some reason, the following script is reading $Question and $TempAnswer, but not $Answer. Please someone tell me what an idiot I am.By the way, this is using Abiword, just change the "Abi" to "Word" and it should work the same. Thanks.Global $Answer = " " Global $TempAnswer = "I have the first card." EnterAQ($TempAnswer) Func EnterAQ($Answer)<{POST_SNAPBACK}>The global variable $Answer is not being set because you are using $Answer as a parameter in the EnterAQ function. Since the parameter is not ByRef, it becomes local within the function, and does not escape the function.Food for thought:1. Why call the function with one variable, and use another variable for the function parameter? Perhaps you just have the variables mixed-up?2. Since you are using Globals, why have a parameter for the function?3. Why use Return in the function if you are not capturing the returned value in the function call? And since the variables are global why return a value? Phillip Link to comment Share on other sites More sharing options...
grakker Posted April 2, 2005 Author Share Posted April 2, 2005 The global variable $Answer is not being set because you are using $Answer as a parameter in the EnterAQ function. Since the parameter is not ByRef, it becomes local within the function, and does not escape the function.Food for thought:1. Why call the function with one variable, and use another variable for the function parameter? Perhaps you just have the variables mixed-up?2. Since you are using Globals, why have a parameter for the function?3. Why use Return in the function if you are not capturing the returned value in the function call? And since the variables are global why return a value?<{POST_SNAPBACK}>The answer to all 3 = because I'm a pretty crappy programmer. Thank you for the answer, obvious after fixing it. Link to comment Share on other sites More sharing options...
quick_sliver007 Posted April 2, 2005 Share Posted April 2, 2005 If $Answer = 'END' Then Shouldn't that be If $Answer = "END" Then . Link to comment Share on other sites More sharing options...
Developers Jos Posted April 2, 2005 Developers Share Posted April 2, 2005 Shouldn't that be If $Answer = "END" Then<{POST_SNAPBACK}>What is the difference ?? :"> SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
phillip123adams Posted April 2, 2005 Share Posted April 2, 2005 The answer to all 3 = because I'm a pretty crappy programmer. Thank you for the answer, obvious after fixing it.<{POST_SNAPBACK}>Oh, okay! That clarifies things!And, you're welcome. I'm happy it helped. Phillip 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