I am building an application that is supposed to find a file and process it but needs to generate message box alerting user if the file specified doesn't exist. When I run the program and the file does exist, it works flawlessly. However, when I run the program and the file doesn't exist, it literally doesn't do anything. No message box, no errors, absolutely nothing. It behaves as if it ran through the program successfully and performs the me.close at the end of the script. Below is the code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each q As String In Directory.GetFiles("C:\","InSight_Customized_View_Download*.csv")
Dim FILE_NAME As String = q
Dim filename As String = "C:\Error Log\Error Log.txt"
Dim TextLine As String
If File.Exists(FILE_NAME) = True Then
'A bunch of code that executes if file exists. This runs without any issue.
Dim sb As New StringBuilder()
Using objReader2 As New StreamReader(filename)
sb.AppendLine(Today & vbTab & vbTab & "File Does Not Exist")
Dim objWriter As New StreamWriter(filename)
MsgBox("File Does Not Exist")
Even though file does not exist, it does not write to error log nor does it generate message box. It just performs the me.close.