SorryButImaNewbie Posted November 18, 2014 Share Posted November 18, 2014 Hello dear travelers of the web! I have a kind of a basic problem I assume. I'm trying to make a script that try to write a "code" from an array to a textbox, and if the program doesn't accept it moves to the next possible "code". The array is 1D. I think that I will achive this with For...To...Step...Next, but I got a lot of syntax error, also I don't really seems to understand what next is doing excatly. My plan was that the script starts with the first code in the array, and if it detects the specified error massage window, it closes it and try with the next one. (The program is for bug testing in a system and not some low level bruteforce script). It would be nice that if the script runs through the array, it would give an error MsgBox, telling us it has no more possible code for today, but thats just extra toppings on the cake. The root of the problem is that the program only accept the same code twice per day. Also an other problem that in case the program accept the code another window with Információ title is opened, thats why i specify the string on the error message would this If go around till it find an acceptable code in the array? I wanted it that way but again I'm not sure how the enxt works excatly. PS.: Do i use sleeps unnecessarily? Thank you for your help! My code right know is: ControlSend ($handle3, "", "[CLASSNN:TEdit5]",$arrayEuroShell[$i]) ;$i is a local variable decleared as 0 at the start of the function Sleep(200) ControlClick($handle3, "", "[CLASSNN:TBitBtn2]") ;Okey button, trying to send the datas Sleep(1000) If WinExists("Információ", "Elérte a maximális napi vásárlási mennyiséget! ( 2 )" Then WinKill("Információ") WinActivate("Befizetés") WinWaitActive("Befizetés") For $i To $iMax-1 Step 1 ;iMax is the array size, calculated by UBound ControlSend ($handle3, "", "[CLASSNN:TEdit5]",$arrayEuroShell[$i]) Next EndIf Link to comment Share on other sites More sharing options...
Luigi Posted November 18, 2014 Share Posted November 18, 2014 Why not use WinWait instead of Sleep? Visit my repository Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted November 18, 2014 Author Share Posted November 18, 2014 Like WinWait("Information") If WinExist ("Information", "the above text") Then .... code Endif WinWaitActive("Információ")? I think i will have to write WinWaitActive to have the text of the information window when the code is accepted Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted November 18, 2014 Author Share Posted November 18, 2014 Ohh sorry I should have provided the errors as well.... Error is basicly everything in the For To line To has syntax error, $iMax Statement cannot be just an expression. Step is syntax error and the 1 after step has the Statement cannot be just an expression, which is interesting to me since its a number. Next is both a syntax and the expression error and endif also an expression error which I dont even understand. (sorry, still new to autoIT) thanks again Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted November 18, 2014 Author Share Posted November 18, 2014 Ohh sorry I should have provided the errors as well.... Error is basicly everything in the For To line To has syntax error, $iMax Statement cannot be just an expression. Step is syntax error and the 1 after step has the Statement cannot be just an expression, which is interesting to me since its a number. Next is both a syntax and the expression error and endif also an expression error which I dont even understand. (sorry, still new to autoIT) thanks again So I now found what could cause all these errors, dont really knpw why but $i = 0 had to be decleared after the For as well.... Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted November 18, 2014 Author Share Posted November 18, 2014 I modifed my script, now it runs and also reenter to the window I need to work with, but it seems it doesnt go in to the Forcyle (it doesnt start to write anything in to the textbox the 2. time it enters) Link to comment Share on other sites More sharing options...
TheSaint Posted November 18, 2014 Share Posted November 18, 2014 (edited) You are missing the equals bit in your For Next code. For $i To $iMax-1 Step 1 ;iMax is the array size, calculated by UBound ControlSend ($handle3, "", "[CLASSNN:TEdit5]",$arrayEuroShell[$i]) Next should be something like For $i = 1 To $iMax-1 Step 1 ;iMax is the array size, calculated by UBound ControlSend ($handle3, "", "[CLASSNN:TEdit5]",$arrayEuroShell[$i]) Next NEXT tells $i to increment by the STEP value ... or by one if there is no Step value. It will do this until $i equals $iMax - 1 $i starts at the value between equals (=) and TO. In this case 1. Edited November 18, 2014 by TheSaint SorryButImaNewbie 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted November 18, 2014 Author Share Posted November 18, 2014 (edited) You are missing the equals bit in your For Next code. For $i To $iMax-1 Step 1 ;iMax is the array size, calculated by UBound ControlSend ($handle3, "", "[CLASSNN:TEdit5]",$arrayEuroShell[$i]) Next should be something like For $i = 1 To $iMax-1 Step 1 ;iMax is the array size, calculated by UBound ControlSend ($handle3, "", "[CLASSNN:TEdit5]",$arrayEuroShell[$i]) Next Thanks I already modifed it that way (haven't really used this before, so I didn't know that I should write it that way, I just figured it out o my own in time) I dont know why isn't it jumping to the next element of the array and write it to the textbox Edit: Sorry, it actually goes in to the For cyle, tried it with a MsgBox... Edited November 18, 2014 by SorryButImaNewbie Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 18, 2014 Moderators Share Posted November 18, 2014 SorryButImaNewbie,If you say you do not enter the For...Next loop it suggests that the loop end value $iMax - 1 is less than 1, which you set as the start value. Have you done any errorchecking (MsgBox / ConsoleWrite) to see what value you are actually setting at that point? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted November 18, 2014 Author Share Posted November 18, 2014 SorryButImaNewbie, If you say you do not enter the For...Next loop it suggests that the loop end value $iMax - 1 is less than 1, which you set as the start value. Have you done any errorchecking (MsgBox / ConsoleWrite) to see what value you are actually setting at that point? M23 Yeah sorry Melba the $i = 1 as it should be and the $imax is 6 inside the for loop/cyle (dont know how we call them here) these are the values they should have, nothing is written inside the textbox and the script is just standing Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted November 18, 2014 Author Share Posted November 18, 2014 (edited) Today I learned, that if i close a window I need to get a new handle if i open a new one even if its the same... Now my only problem is that it writes the full array when it open the widow a 2. time, how do I stop that? I need only the next one (also for some reason if i dont stop it goes till Array variable has incorrect number of subscripts or subscript dimension range exceeded.: I'm sure that this means it wants to open array[6] while after the To i clarify it that it should only goes till 5 ($imax(6) - 1 = 5 ) Edited: I "danced" around the problem, by clicking the okey button inside the for loop, but now I'm basicly stuck in it... (my code may make it a bit clearer) Local $handle3 = WinGetHandle("Befizetés") ControlSend($handle3, "", "[CLASSNN:TComboBox3]", "ü{ENTER}") ControlSend($handle3, "", "[CLASSNN:TEdit5]", $arrayEuroShell[$i]) ;$i is a local variable decleared as 0 at the start of the function Sleep(200) ControlClick($handle3, "", "[CLASSNN:TBitBtn2]") ;Okey button WinWait("Információ") If WinExists("Információ", "Elérte a maximális napi vásárlási mennyiséget! ( 2 )") Then WinKill("Információ", "Elérte a maximális napi vásárlási mennyiséget! ( 2 )") ControlFocus($handle, "", "TEdit1") Send("{CTRLDOWN}v{CTRLUP}") ControlClick($handle, "", "[CLASSNN:TAdvBitBtn23]") WinWaitActive("Befizetés") For $i = 0 To $iMax - 1 Step 1 Local $handle3 = WinGetHandle("Befizetés") ControlSend($handle3, "", "[CLASSNN:TComboBox3]", "ü{ENTER}") ControlSend($handle3, "", "[CLASSNN:TEdit5]", $arrayEuroShell[$i + 1]) ControlClick($handle3, "", "[CLASSNN:TBitBtn2]") ;MsgBox(0,"teszt","i:" & $arrayEuroShell[$i+1] & "imax:" & $iMax) Next EndIf WinWaitActive("Információ", "Sikeres jegyvásárlás!") ControlClick("Információ", "Sikeres jegyvásárlás!", "[CLASSNN:TBitBtn1]") Edited November 18, 2014 by SorryButImaNewbie Link to comment Share on other sites More sharing options...
TheSaint Posted November 18, 2014 Share Posted November 18, 2014 Doesn't appear to be the full code, as I don't know where $arrayEuroShell is created (coming from), or what the value of $i is in first use. I also don't know where $iMax is from either. You need to use Msgbox's to check on variable values and help develop your logic flow. Quite possibly you need $iMax to equal or be replaced by $arrayEuroShell[0] to get real total? Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted November 18, 2014 Author Share Posted November 18, 2014 (edited) $arrayEuroShell is inside the script written by me, it consists all the codes I have that is accepted by the program im working on, I plan to make it bigger when i finish the code, for now it has 6 elements. $iMax is the number of elements inside the EuroShell array, i calculate its value by UBound. I know that my logic flow is that once I get in to the for loop my the script is basicly stuck there and I have to make it so it returns to the next line of script (after EndIF) once it finds an acceptable code, and writes it in to the TextBox. The problem is that I don't know how to do that. (sorry, I work for a company, I'm just an intern with a frsh BSc, and a programmer left the company and they gave me his job, since i had programming exp with C#, I never used autoIT before. I really like it, as I start to see how multifunctinal and usefull tool it is, but im still very far away from mastering it. The point is my boss isn't really happy with me if I post the full code of any function, don't really know how could it be harmfull for the company but orders are orders ) Edited November 18, 2014 by SorryButImaNewbie Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted November 19, 2014 Author Share Posted November 19, 2014 I'm trying a new solution, and it works almost perfectly. I use do until loop and it gets its job done (even if this is not the most effective way to do it), but seems to stuck at the end of until, when it receives the message box it waited for code is the following: If WinExists("Információ", "Elérte a maximális napi vásárlási mennyiséget! ( 2 )") ThenDoWinKill("Információ", "Elérte a maximális napi vásárlási mennyiséget! ( 2 )") ;message about code used 2 today already$i = $i + 1ControlFocus($handle, "", "TEdit1") ;entering the specification to the window/form where I try the next codeSend("{CTRLDOWN}v{CTRLUP}")ControlClick($handle, "", "[CLASSNN:TAdvBitBtn23]")WinWaitActive("Befizetés")Local $handle3 = WinGetHandle("Befizetés") ;adding the specification to the window/form where I try the next codeControlSend($handle3, "", "[CLASSNN:TComboBox3]", "ü{ENTER}")ControlSend($handle3, "", "[CLASSNN:TEdit5]", $arrayEuroShell[$i])ControlClick($handle3, "", "[CLASSNN:TBitBtn2]")Sleep(1000)Until WinActive("Információ", "Sikeres jegyvásárlás!") ;message of succesfull code entryMsgBox(0, "Teszt", "Jelentem ki jöttünk a Do.... Until ágból!") ;test MsgBox;~ ----------------------------------------------------???????????????????????????????????????????????????-------------------------------------- ;here is where i stuck (messagebox doesnt apper)EndIf Local $handleinfo = WinGetHandle("Információ", "Sikeres jegyvásárlás!")ControlClick($handleinfo, "", "[CLASSNN:TBitBtn1]") Link to comment Share on other sites More sharing options...
Solution SorryButImaNewbie Posted November 19, 2014 Author Solution Share Posted November 19, 2014 (edited) During my journey to solve it i dumped For.. To and replaced it with Do.. Until not sure if this is the best solution, but this is the way i went at the end For some reason it seems that DO Until wanted to run one more time after Until expression was fulfilled sine the Befizetés Form was never got activated again, it stopped there. I commented it out and used a Sleep(1000) instead, which allowed it to continue the script, and now it works. I found this out with Opt("TrayIconDebug", 1) thanks for Alienclone! Thank you everyone for your help so far! PS.: Any idea why Do... Until wanted to run one more time? (Edited for PS, and for thanks note) Edited November 19, 2014 by SorryButImaNewbie 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