Vitaliy4us

How to exit from script but not from the program?

8 posts in this topic

#1 ·  Posted (edited)

I have a parent script which includes some other scripts. They are executed one by one. If a problem occures in one of them the script should be scipped and the next one should start. How I can do this. Exit stops the parent scripts, goto is missing. Should I use loop? But it looks not good enough. Is there any other way?

Edited by Vitaliy4us

Share this post


Link to post
Share on other sites



#2 ·  Posted

Hard to tell without having seen your code.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

@Vitaliy4us it is extremely difficult to give you suggestions with no code to go on. Typically, you would put your code into functions in a single script, or if it is repeatable code you could create a UDF and call it from your main script. How you exit the function, whether in the main script or a UDF, will determine what happens with the rest of the script. Again, tho, it's difficult to drill down to specifics without seeing how your code is laid out.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#4 ·  Posted

This is the code:

;Test suit #1

#include "commonConstantsAndFunctions.au3"

Local $log = "testsuit1.log"


FileWrite($log, "Test suit number 1" & @CRLF & @CRLF)

#include "test1_1.au3"
MsgBox(0, "Test suit 1", "Test 1_1 finished", 2)

#include "test1_2.au3"
MsgBox(0, "Test suit 1", "Test 1_2 finished", 2)

#include "test1_3.au3"
MsgBox(0, "Test suit 1", "Test 1_3 finished", 2)

#include "test1_4.au3"
MsgBox(0, "Test suit 1", "Test 1_4 finished", 2)

MsgBox(0, "Test results", "Test suit 1 is finished", 10)

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

Can you please post one of the test1_*.au3 includes so we can see how you call the code in there?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

9 minutes ago, water said:

Can you please post one of the test1_*.au3 includes so we can see how you call the code in there?

;Test 1_1. Send fax without attachments.

#include "commonConstantsAndFunctions.au3"
#include "SysTrayUDF.au3"
#include <Date.au3>


Local $testName = "Test 1_1. Send fax without attachments."
Local $subj = $testName & " " & _now()
Local $body = "This is an automation fax for testing fax sending without attachments"

If ProcessExists($ClientProcessName) == 0 Then
    ReloadClient($clientAccounLoginGW, $clientAccounPasswordGW) ;For example if a problem occures here, the script should stop
                                                                ;and the next one (test1_2.au3) should to continue
EndIf

OpenFromTray("New fax")

Local $ParameterExpectedValue = True
Local $ParameterValue = SendFax(1000,$subj, $body, "")

WriteToLog($ParameterValue, $ParameterExpectedValue, $testName & " is OK", $testName & " FAILED", False)

 

Edited by Vitaliy4us

Share this post


Link to post
Share on other sites

#7 ·  Posted

As suggested " put your code into functions".

; Test suit #1

#include "commonConstantsAndFunctions.au3"
#include "test1_1.au3"
#include "test1_2.au3"
#include "test1_3.au3"
#include "test1_4.au3"

Local $log = "testsuit1.log"
FileWrite($log, "Test suit number 1" & @CRLF & @CRLF)

test1_1()
MsgBox(0, "Test suit 1", "Test 1_1 finished", 2)

test1_2()
MsgBox(0, "Test suit 1", "Test 1_2 finished", 2)

test1_3()
MsgBox(0, "Test suit 1", "Test 1_3 finished", 2)

test1_4()
MsgBox(0, "Test suit 1", "Test 1_4 finished", 2)

MsgBox(0, "Test results", "Test suit 1 is finished", 10)

test1_1.au3:

;Test 1_1. Send fax without attachments.

#include "commonConstantsAndFunctions.au3"
#include "SysTrayUDF.au3"
#include <Date.au3>

Func Test_1_1()
    Local $testName = "Test 1_1. Send fax without attachments."
    Local $subj = $testName & " " & _now()
    Local $body = "This is an automation fax for testing fax sending without attachments"

    If ProcessExists($ClientProcessName) == 0 Then
        ReloadClient($clientAccounLoginGW, $clientAccounPasswordGW)
    EndIf
    
    ; If error occurs then end this test and return to the main script
    If @error = 1 Then Return
    
    OpenFromTray("New fax")

    Local $ParameterExpectedValue = True
    Local $ParameterValue = SendFax(1000,$subj, $body, "")

    WriteToLog($ParameterValue, $ParameterExpectedValue, $testName & " is OK", $testName & " FAILED", False)
EndFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

7 minutes ago, water said:

As suggested " put your code into functions".

Thank you, it looks much better then using loop/ExitLoop. The only problem is to refurbish 2 hundreds scripts...

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