Ok, the following code I’m reading in a text file and searching for a specific string in a line. If the string is found, I don’t want to do anything and if it’s not found, I want to do something else. Right now I have a msgbox for each condition.
The problem I have, is when string is not found, it’s not triggering the msgbox. The other msgbox triggers when the string is found though.
Any ideas?
Dim logfile() As String = System.IO.File.ReadAllLines("C:\Temp\Transfer_Log.txt")
Dim searchstring As String = "Test_" + DateTimePicker2.Value.ToString("yyyyMMdd") + ".csv"
For Each line As String In Filter(logfile, searchstring)
If line.Contains("Test_" + DateTimePicker2.Value.ToString("yyyyMMdd") + ".csv") Then
MsgBox("Do Nothing") 'THIS WORKS
Else
MsgBox("Append") 'THIS DOES NOT WORK
End If
Next
If I’m interpreting your code correcty,
Filteris a filtering funciton that is returing all lines that match the text"Test_" + DateTimePicker2.Value.ToString("yyyyMMdd") + ".csv". Then you are looping through each line and again comparing it to see if it matches"Test_" + DateTimePicker2.Value.ToString("yyyyMMdd") + ".csv". So your second message box will never be called, ever. I would suggest this,According to the question, you want to know if the string exists in the file or not, and this will tell you if it does or not.