What do I need to do to the code I have to make it so it will catch errors, AND write to a .txt file for EACH test case in a spreadsheet?
- Expected behavior:
The script begins using a spreadsheet to drive the number of times this script will loop. An error is purposely generated early in the loop. The TryCatch finds the error, writes it to the console each time the error happens, then continues the loop no matter how many entries there are in the driver spreadsheet after the error.
- Actual behavior:
The script begins using a spreadsheet to drive the number of times this script will loop. An error is purposely generated early in the loop. The TryCatch finds the error, it is written to the console, but only finishes one iteration of three. It should continue to the other two test cases, but does not.
- The Code:
Public Sub Main
Dim row As ActiveDataRow
Dim datetimefilename As String = DateTime.Now.ToString("_MM-dd-yyyy_HHmmss")
With _desktop.BrowserApplication()
.SetActive()
.Maximize()
With .BrowserWindow("@url='*.com*'")
Try
For Each row In data
rowno = row.RowNumber
args("testcase") = data.Item(rowno).GetString("testcase")
args("firstname") = data.Item(rowno).GetString("firstname")
args("midname") = data.Item(rowno).GetString("midname")
args("lastname") = data.Item(rowno).GetString("lastname")
Call ConsoleOutput(args)
Call FileOutput(args)
Call TryCatch()
Next
Catch ex As Exception
Dim msg As String
If Err.Number <> 0 Then
msg = "Error #" & Str(Err.Number) & " was generated by " & ex.Source & Chr(13) & ex.Message & ", " & ex.HelpLink & ", " & Err.HelpContext
MsgBox (msg, MsgBoxStyle.MsgBoxSetForeground, "Error Handling using Try/Catch/Finally") 'TRYCATCH - message box error display
' Dim filenamedatetime As String = DateTime.Now.ToString("MM-dd-yyyy_HHmmss")
' Dim filename As String = "C:\Users\Public\Desktop\MyPri_OutputTest\ZZZ_TryCatch_" & filenamedatetime & ".txt"
' Using sw As StreamWriter = File.AppendText(filename)
' sw.WriteLine(msg)
' End Using
'/
End If
'/
Finally
End Try
End With
.Close()
End With
End Sub 'Main