Jump to content

Wrapping head around For...To...Step...Next nested in If


Go to solution Solved by SorryButImaNewbie,

Recommended Posts

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

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

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

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 by TheSaint

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)

userbar.png

Link to comment
Share on other sites

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 by SorryButImaNewbie
Link to comment
Share on other sites

  • Moderators

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? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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? :huh:

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

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 by SorryButImaNewbie
Link to comment
Share on other sites

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)

userbar.png

Link to comment
Share on other sites

$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 by SorryButImaNewbie
Link to comment
Share on other sites

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 )") Then
Do
WinKill("Információ", "Elérte a maximális napi vásárlási mennyiséget! ( 2 )") ;message about code used 2 today already
$i = $i + 1
ControlFocus($handle, "", "TEdit1") ;entering the specification to the window/form where I try the next code
Send("{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 code
ControlSend($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 entry
MsgBox(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

  • Solution

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 by SorryButImaNewbie
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...