Sign in to follow this  
Followers 0
AIusers

Running a Script from an arbitrary step

7 posts in this topic

Hi,

I guess I'm looking for some in general help. I've written a script that has a structure like the code below. My issue is that I don't want to always start from Step 1. Sometimes I want to start the script from a later step. I hoped to use a GUI to be able to enter in the Step number I would like to start from, but I wasn't sure how the flow would work. The idea would be to enter the step number into the GUI and then have the script start from that step and continue on doing the remaining steps afterward. I was thinking that a case statement would allow the input of the initial step, but not sure how to force it into taking the next step from there. My code will end up having over 100 steps...

Thanks!

Func Main()
    Step1()
    Step2()
    Step3()
    ;etc etc
    Step20()
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi, Alusers, welcome to the forum. Something like this? Rough script only, to give you ideas:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

GUICreate("Test", 300, 250)
$input = GUICtrlCreateInput("", 10, 10, 280, 30)
$btnGo = GUICtrlCreateButton("Go", 10, 200, 30, 30)


GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btnGo
                Switch GUICtrlRead($input)
                    Case 1
                        Step1()
                    Case 2
                        Step2()
                    Case 3
                        Step3()
                    Case Else
                        MsgBox($MB_SYSTEMMODAL, "", "Error reading input")
                EndSwitch
        EndSwitch
    WEnd

GUIDelete()

 

Edited by JLogan3o13

When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi JLogan3o13,

Thank you for quick reply! In your example, if someone entered 2 in order to have the script run from step 2, what would happen after Step 2 completed? Would it launch step3 automatically and so on? I don't want to the user to need to type in all of the remaining steps. One difficult solution that I've come up with was to have a case statement that was setup as a wrapper that would call the remaining steps that are needed. Unfortunately as the number of steps grows, this solution gets quite large. For Example

...

Case 45 ; The user would like to start from step 45, so we need to run steps 45 through 100
    Step45()
    Step46()
    Step47()
    ;etc
    
Case 46 ; The user would like to start from step 46...
    Step46()
    Step47()
    Step48()
    ;etc
    
etc
etc

 

 

 

Edited by AIusers
Added comments for clarity

Share this post


Link to post
Share on other sites

Just to clarify the detail (missing from your first point): You have x number of steps, and you want the script to begin on the step specified in the GUI, and then continue through the remaining steps, am I correct? If I am correct, a couple of follow up questions:

  • Are the steps (functions) always sequential?
  • Have you thought about having each "step" check for success and then call the next step itself? Something like this (pseudo):
Func Step45()
   ;do stuff
   
   If $stuff = @error then
      Exit(MsgBox($MB_SYSTEMMODAL, "", "Failed on Step 45!"))
   Else
      Step46()
   EndIf
EndFunc

 


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

You are completely correct and yes, the steps are always sequential. Would nesting the functions like you said be an issue if the last step called the first and began the entire process all over again? An example:

I enter the number 47 into the GUI.

Steps 47 through 100 in the script are run in order by nesting the next function needed. 

The script processes step 100 and the last line in it is a call to step1(). 

The script continues processing from step 1 and runs in order through the steps forever (or until I break it out).  

 

 

Share this post


Link to post
Share on other sites

Would it cause an issue? I guess the answer is "No, not if that is what you want to happen and you code to break out of the loop when you need to". I guess without knowing more about exactly what you're trying to do that is the best answer I can give :)


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Yes, sorry my last question was very open ended and not easy to answer. I will try your approach by nesting the function calls. I was concerned that it would be sloppy, or could cause an issue if there were too many functions, calling even more functions, possibly hundreds of times. In any case, thank you for taking the time to help me!

I just realized how difficult maintaining the solution I suggested would be if I added additional steps... Not only would I need to add the new steps, which wouldn't be so bad since they were at the end, but I would need to go back to all of the original steps and add them into those as well. Thanks again!

Edited by AIusers

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