Sign in to follow this  
Followers 0
JohnBailey

Code Efficiency

4 posts in this topic

My apologies for the bad title

I want the for statement to pick-up where it left off last time the function was called. Here's what I've got, but there MUST be a better way. The For statement is inside of a function.

It would make much more sense to have For $i to "a hundred more". Any ideas

If $number = 1 Then
        For $i = 1 To 100
            $variable = $array[$i]&' '
            ControlSend($Win_Title, $Win_Text, $Control_ID, $variable)
        Next
    ElseIf $number = 2 Then
        For $i = 101 To 200
            $variable = $array[$i]&' '
            ControlSend($Win_Title, $Win_Text, $Control_ID, $variable)
        Next
    ElseIf $number = 3 Then
        For $i = 201 To 300
            $variable = $array[$i]&' '
            ControlSend($Win_Title, $Win_Text, $Control_ID, $variable)
        Next
    ElseIf $number = 4 Then
        For $i = 301 To 401
            $variable = $array[$i]&' '
            ControlSend($Win_Title, $Win_Text, $Control_ID, $variable)
        Next
    ElseIf $number = 5 Then
        For $i = 401 To 501
            $variable = $array[$i]&' '
            ControlSend($Win_Title, $Win_Text, $Control_ID, $variable)
        Next
    ElseIf $number = 6 Then
        close()
    EndIf

A decision is a powerful thing

Share this post


Link to post
Share on other sites



This does it

Local $array
Local $ii = 1
Local $iii = 100

MsgBox(0,"Dialog",$ii &" to "&$iii)
goForward()

Func goForward()
For $i = $ii To $iii
    ControlSend("Untitled - Notepad","","Edit1",$array[$i]&" ")
    $iii = $ii + 99
    $ii = $i
Next
MsgBox(0,"Dialog",$ii &" to "&$iii)
goForward()
EndFunc

A decision is a powerful thing

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

maybe...

Func DoIt($Num)
    Local $bNum = ($Num * 100)
    Local $aNum = ($bNum - 99)
    For $i = $aNum To $bNum
        $variable = $array[$i]&' '
        ControlSend($Win_Title, $Win_Text, $Control_ID, $variable)
    Next
EndFunc

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Valuater, I like the logic of that much better. I did the following; what do you think?

Local $i
Local $ii = 1
Local $iii
Local $iv
Func goForward()
    If $iii < $ArrayMax Then
        Local $iii = ($ii * 100)
        Local $iv = ($iii - 99)
        $ii = $ii+1
        For $i = $iv To $iii
            ControlSend("Untitled - Notepad","","Edit1",$array[$i]&@CR)
            If @error Then ExitLoop
        Next
        goForward()
    Else
        MsgBox(0,"Dialog","Done!")
    EndIf
EndFuncoÝ÷ ÙhrÉ÷öÛaÌ(®H§wöÉèµìb¶)ඥ¢HË^iØ­zºè®Ê.µ©ÝrZ,zÆ®¶­sd6öçG&öÅ6VæBgV÷CµVçFFÆVBÒæ÷FWBgV÷C²ÂgV÷C²gV÷C²ÂgV÷C´VFCgV÷C²Âb33c¶'&²b33c¶Òf×´5" bW'&÷"FVâWDÆö÷

A decision is a powerful thing

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