Hi, I have a working script where I am trying to exit 2 (two) for loops after a condition is met. Can you help? I included the snippet that is in question and the entire script which is below.
Thank-you
Here is the snippet:
If n = 3 Then
print "Terminated after" & n & " loops"
'I want to exit both loops here.
End If
Next
Next
Loop
Here is the complete script:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' File Name: Read Last 6 Lines of Log file
'' Purpose: Read Last 6 Lines of Log file
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim arrFileLines(), s1, logfile
logfile = DataTable("Visible", dtLocalSheet)
'Loop
Do Until TextFound1
ForReading = 1 'Reads contents of entire file and then stores into an array
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\nelson\Desktop\cli.log", 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
'print i 'prints # of lines in file
Loop
objFile.Close 'Closes file
For l = Ubound(arrFileLines) -6 to Ubound(arrFileLines) 'UBound function returns upper limit for # of elements in array
For n = 1 to 4 'loop break out start
If arrFileLines(l) = logfile Then
TextFound1 = True
print "!!!!!!!!!!!!!!!!!!!!! The text " & "'" & logfile & "'" & " was found !!!!!!!!!!!!!!!!!!!!!."
print vbcr
Reporter.ReportEvent 0, "Command Results:", logfile & " command ran successfully."
Exit For
' ElseIf n = 4 Then
' print n & "Exit Test after 4 loops"
' ExitTest
Else
print l & " The text " & "'" & logfile & "' " & " was not found."
print "Text " & "'" & arrFileLines(l) & "'" & " was found instead. "
print vbcr
End If
wait 2
print "Iteration " & n
If n = 3 Then
print "Terminated after" & n & " loops"
'go to another action
'what i really want to do is exit both for loops
ExitTest
End If
Next
Next 'end loop break out
Loop
Thank-you
Here is the snippet:
If n = 3 Then
print "Terminated after" & n & " loops"
'I want to exit both loops here.
End If
Next
Next
Loop
Here is the complete script:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' File Name: Read Last 6 Lines of Log file
'' Purpose: Read Last 6 Lines of Log file
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim arrFileLines(), s1, logfile
logfile = DataTable("Visible", dtLocalSheet)
'Loop
Do Until TextFound1
ForReading = 1 'Reads contents of entire file and then stores into an array
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\nelson\Desktop\cli.log", 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
'print i 'prints # of lines in file
Loop
objFile.Close 'Closes file
For l = Ubound(arrFileLines) -6 to Ubound(arrFileLines) 'UBound function returns upper limit for # of elements in array
For n = 1 to 4 'loop break out start
If arrFileLines(l) = logfile Then
TextFound1 = True
print "!!!!!!!!!!!!!!!!!!!!! The text " & "'" & logfile & "'" & " was found !!!!!!!!!!!!!!!!!!!!!."
print vbcr
Reporter.ReportEvent 0, "Command Results:", logfile & " command ran successfully."
Exit For
' ElseIf n = 4 Then
' print n & "Exit Test after 4 loops"
' ExitTest
Else
print l & " The text " & "'" & logfile & "' " & " was not found."
print "Text " & "'" & arrFileLines(l) & "'" & " was found instead. "
print vbcr
End If
wait 2
print "Iteration " & n
If n = 3 Then
print "Terminated after" & n & " loops"
'go to another action
'what i really want to do is exit both for loops
ExitTest
End If
Next
Next 'end loop break out
Loop