Sign in to follow this  
Followers 0
leuce

Increase Number Of For-next Loops From Within The Loop

4 posts in this topic

G'day everyone

Can I do a For...Next loop in which the number of loops are changed from within the loop itself?

I need a certain function to perform itself once only if one condition occurs, but if a different condition occurs, I want the function to repeat itself (again, checking if the condition occurs, and performing itself once only if that condition occurs only once the second time). Theoretically this could result in an endless loop if the condition keeps occuring, but that's not a problem.

I'm using a translation program, OmegaT. In OmegaT, TAB moves to the next segment (the next sentence, in other words). If the sentence contains the character "X", I want OmegaT to skip that segment and go directly to the next segment. If the next segment contains "X", then again, and again until it reaches a segment that doesn't contain "X".

Or, if this isn't possible, can you think of another method which might do the trick?

This is what I have, but it only loops once:

HotKeySet ("^{ENTER}", "Autoskip")

While 1
Sleep (10000)
WEnd

Func Autoskip()

WinWaitActive ("OmegaT", "")

$a = 1

; Move to the next segment

Send ("{TAB}")

For $b = 1 to $a

; Copies segment content to clipboard, then to $c, and
; then checks to see if it contains the character "X"

Send ("^a")
Send ("^c")
Send ("^{HOME}")

$c = ClipGet()
$d = StringInStr ($c, "X")

; If not, then do nothing.

If $d = 0 Then 
Sleep(100)

; If yes, then move directly to the next segment

Elseif $d <> 0 Then
Send ("{TAB}")

; Increment the For value with one so that theortically
; it will will perform the loop one time extra.

$a = $a + 1
EndIf

Next

EndFunc

Exit

Thanks!

Samuel

Share this post


Link to post
Share on other sites



G'day everyone

Can I do a For...Next loop in which the number of loops are changed from within the loop itself?

I need a certain function to perform itself once only if one condition occurs, but if a different condition occurs, I want the function to repeat itself (again, checking if the condition occurs, and performing itself once only if that condition occurs only once the second time). Theoretically this could result in an endless loop if the condition keeps occuring, but that's not a problem.

I am guessing that you could just do an If Statement, and hoping I actually understand that question:
While 1
    If $Var = True Then
        For $i = 1 To Ubound($Array) - 1;(Or some number)
           ;Do Something
        Next
    EndIf
WEnd

I'm using a translation program, OmegaT. In OmegaT, TAB moves to the next segment (the next sentence, in other words). If the sentence contains the character "X", I want OmegaT to skip that segment and go directly to the next segment. If the next segment contains "X", then again, and again until it reaches a segment that doesn't contain "X".

Or, if this isn't possible, can you think of another method which might do the trick?

If it's a Control, then maybe you can something like:
$Text = ControlGetText('WindowName', '', 'ControlID or ClassNameNN')
$StoreInArray = StringSplit($Text, @CRLF); Replace with @TAB if it's seperated by tabs
For $i = 1 To UBound($StoreInArray) - 1
    MsgBox(0, 'Info', $StoreInArray[$i])
Next

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I dont quite understand all you want to do, but try using this

WinWaitActive("OmegaT","")
Sleep(1000)
Send ("^a")
Send ("^c")
Send ("^{HOME}")
$c = ClipGet()

While 1
Send ("^a")
Send ("^c")
Send ("^{HOME}")
$c = ClipGet()
If StringInStr ($c, "X") then
Send("{TAB}")
EndIf
Wend

^^ i think this should work, its just a more simplified version of what you had, with an extra loop

Edit: Beat me Smoke

Oh well, yours was better anyways :)

Edited by Paulie

Share this post


Link to post
Share on other sites

I dont quite understand all you want to do, but try using this...

Thanks Paulie and Smoke_N for your answers. Paulie, I used your solution and made an adaptation to it, which works beautifully:

WinWaitActive("OmegaT","")
Send("{TAB}")

$i = 1

While $i = 1
Send ("^a")
Send ("^c")
Send ("^{HOME}")
$c = ClipGet()
If StringInStr ($c, "X") then
Send("{TAB}")
$i = $i - 1
EndIf
$i = $i + 1
Wend

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