0
votes

So...I've been at this for a while but am definitely still horrible at it.

To summarize:

I'd like to start the next iteration of the loop after clicking specific options in certain guis.

In my research I've discovered that you can't have any returns in the loop. The problem is I have no idea how to make this work without returns.

Please HELP!

Thanks,

Marc S

(TRIMMED!)

` Startline := 5

                Loop, 10
            {
                         CurrentRow := (StartLine - 1) + A_Index ;*****

                        ;----------------***GETTING THE DATA***----------------
                        ControlFocus,, Proto_Names - Excel 
                        Sleep, 200
                        oNamesDoc := ComObjActive("Excel.Application")
                        Global AlertStatus := oNamesDoc.Range("C" CurrentRow).Text
                        Global AlertQualifier := oNamesDoc.Range("D" CurrentRow).text
                        Global First := oNamesDoc.Range("H" CurrentRow).text
                        Global Last := oNamesDoc.Range("I" CurrentRow).text
                        Global State := oNamesDoc.Range("J" CurrentRow).text
                        Global Type := oNamesDoc.Range("M" CurrentRow).text
                        Global HMSStatus := oNamesDoc.Range("P" CurrentRow).text
                        Global HMSQualifier := oNamesDoc.Range("Q" CurrentRow).text
                        Global LicenseNo := oNamesDoc.Range("N" CurrentRow).text
                        Global Scrubbed := oNamesDoc.Range("AB" CurrentRow).value
                        ;----------------***GETTING THE DATA***----------------

            ;Gui
                            Gui, 2:Add, Text,x1 y8, Blah Blah
                            Gui, 2:Add, Button, x1 y40, License
                            Gui, 2:Add, Button, x80 y40, Name 
                            Gui, 2:Show, , blah blah - Row %CurrentRow% ; Important because it references A_Index
                        return

                                2GuiClose:    
                                    Gui, 2:Destroy  
                                return        

                                2ButtonLicense:
                                    Gui, 2:Submit 
                                    Gui, 2:Destroy  
            ;Another GUI
                                        Gui, 3:Add, Text,x1 y8, Text
                                        Gui, 3:Add, Text,x170 y132, Row %CurrentRow%  ;Important because it references A_index
                                        Gui, 3:Add, Button,x1 y125 , blah
                                        Gui, 3:Show, , blah blah

                                        return

                                            3GuiClose:     
                                                Gui, 3:Destroy  
                                            return        

                                            3ButtonAgree:
                                                Gui, 3:Submit  
                                                Gui, 3:Destroy  
                                                MsgBox, Click OK for Next
                                            continue 
            } 

`

To summarize further:

Goal: Loop the following: 1. Gui #1: option a | option b also would like to display the A_Index

If option A or B is chosen, goto Gui #2

  1. Gui #2: option c | option d also would like to display the A_Index

If option c, start next iteration of loop from gui 1.

If option d, goto Gui #3

  1. Gui #3: Checkbox E|F|G|H

If any option is selected, i'd like to update a xslx file (i can figure that part out) and then start the next iteration of the loop.

2
Hey, welcome to Stack Overlfow! Try trimming down the wall-of-code to a short, easy to read snippet that demonstrates what you mean. That might make your problem clearer.DanM7
DanM7 - Thanks for the welcome. I trimmed it up.Marc Starr

2 Answers

0
votes

The documentation for Loop suggests you can used break to exit the loop early. Is this what you are trying to achieve with the return?
You could set a return variable, break, and return that?

Edit after clarification:

I think the best way to do this would be to separate each gui out as a function, that just runs the loops you use here.

Have a main loop, and a global variable saying what the next loop to enter is.
Then each function can set this variable.

global NextLoop:=1
main(){
    global NextLoop
    loop{
        if NextLoop == 1 {
            gui1()
        }else if NextLoop == 2 {
            gui2()
        } ; etc...
    }
}
gui1(){
    global NextLoop
    loop{
        if ; user chooses an option {
            NextLoop := 2
            return
        }
    }
} 
gui2(){
    global NextLoop
    loop{
        if ; user chooses c {
            NextLoop := 1
            return
        }

        if ; user chooses d {
            NextLoop := 3
            return
        }
    }
}

} 

Fill out that code, and it should work.

0
votes

Thanks for the suggestion but I think I have it figured out. Check out the code below and I'll try to answer any questions. It's so pretty....

LoopTot := (Endline - StartLine) + 1 

Loop, %LoopTot% ;***Starts the loop***
{ 

Global CurrentRow := (StartLine - 1) + A_Index

;----------------***GETTING THE DATA***----------------
ControlFocus,, Proto_Names - Excel 
Sleep, 200
oNamesDoc := ComObjActive("Excel.Application")
Global AlertStatus := oNamesDoc.Range("C" CurrentRow).Text
Global AlertQualifier := oNamesDoc.Range("D" CurrentRow).text
Global First := oNamesDoc.Range("H" CurrentRow).text
Global Last := oNamesDoc.Range("I" CurrentRow).text
Global State := oNamesDoc.Range("J" CurrentRow).text
Global Type := oNamesDoc.Range("M" CurrentRow).text
Global HMSStatus := oNamesDoc.Range("P" CurrentRow).text
Global HMSQualifier := oNamesDoc.Range("Q" CurrentRow).text
Global LicenseNo := oNamesDoc.Range("N" CurrentRow).text
Global Scrubbed := oNamesDoc.Range("AB" CurrentRow).value
;----------------***GETTING THE DATA***----------------

    Gui, 2:font, s12, Verdana
    Gui, 2:Add, Text,x1 y8, %First% %Last% License:%LicenseNo%
    Gui, 2:Add, Button, x1 y40, License
    Gui, 2:Add, Button, x80 y40, Name 
    Gui, 2:Show, , Search Options - Row %CurrentRow%

  WinWaitClose, Search Options - Row %CurrentRow% 

  If Var = 1

    Continue 

  If Var = 2

    Continue

} 

msgbox DONE!
ExitApp 



2ButtonLicense: 

    Var = 1

    Gui,  2:Destroy 

    CALicense1()

    LicenseAgreeDisagree()

return
return



  2ButtonName:

        Var = 2

        Gui,  2:Destroy 

    CAName1()

    NameAgreeDisagree()

return 
return