I've been trying to get my head round a problem for days now, hope someone can help.
I want to read 'File.ini' line by line checking if specific text exists in the file and then display on a windows form weather particular settings are turned on or off.
So far this code works if "TargetText" exists but if it doenst I get an error on the code line: "If line.Contains("TargetText") Then".
It works if "TargetText" existin in a line in the file but if it doesnt exist I get the 'Null Reference Exception. Object reference not set to an instance of an object.' Any suggestions greatfully recieved!
I want to read 'File.ini' line by line checking if specific text exists in the file and then display on a windows form weather particular settings are turned on or off.
So far this code works if "TargetText" exists but if it doenst I get an error on the code line: "If line.Contains("TargetText") Then".
VB.NET:
Using z As System.IO.StreamReader = New System.IO.StreamReader(File.ini")
Dim line As String
' Read first line.
line = z.ReadLine
' Loop over each line in file, While list is Not Nothing.
Do While Not (line.Contains("TargetText"))
' Read in the next line.
line = z.ReadLine
If line.Contains("TargetText") Then
' code to execute if the text exists in the file
Exit Do
End If
Loop
End Using
It works if "TargetText" existin in a line in the file but if it doesnt exist I get the 'Null Reference Exception. Object reference not set to an instance of an object.' Any suggestions greatfully recieved!
Last edited: