1.

Solve : VB path problem... File not found?

Answer»

I made sure the file exists and I'm still getting problems.
Code: [Select]A first chance exception of type 'System.IO.FileNotFoundException' occurred in Microsoft.VisualBasic.dllCode: [Select]Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser _
("C:\Documents and Settings\Nick\Desktop\readertest.txt")I'm a VB6 Programmer, so forgive me for my ignorance-


If my knowledge of .NET is correct, "using" is used to specify what assemblies and classes you would like to use without qualifying their names fully; for example:
Code: [Select]Using Microsoft.VisualBasic.FileIO.*
the way your using it now, it would seem more appropriate to use the Dim statement, as in:

Code: [Select]Dim MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser _
("C:\Documents and Settings\Nick\Desktop\readertest.txt")
yeah, i guess that makes sense. I got my snippet from MSDN so it might not be express 2005 formatted or whatever. but that will make it read the file then?or maybe you can just help with all new code. I want to read text out a text file, and SET it as variables to be used later. the thing is I need like probably about 20 variables in the text file.Quote

I made sure the file exists and I'm still getting problems.

How did you check?

Code: [Select]If My.Computer.FileSystem.FileExists("c://Check.txt")
MsgBox("File found.")
Else
MsgBox("File not found.")
End If

By the way, if your file is delimited, you were on the right track with Using MyReader:

This is the entire snippet from the MSDN help:
Code: [Select]Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser("C:\Documents and Settings\Nick\Desktop\readertest.txt")
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
MsgBox(currentField)
Next
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
End Using

Good LUCK. Sorry Gamerx365, LOOKS like I sent you down the wrong path.

I never said I was a .NET programmer.Quote from: Sidewinder on September 26, 2008, 02:31:42 PM
Quote
I made sure the file exists and I'm still getting problems.
How did you check?
i made sure it was there, and also I checked the path from the PROPERTIES. I've tried the file in different places also.Quote
i made sure it was there, and also I checked the path from the properties

Please explain. Have you checked the file existence with program code? Is Nick your userid? You may not have permissions for the file.

Only other thing I can think of is the hidden attribute of the file is flipped on.


well i CREATED the file right before trying this. Yes i'm using nick as my userid. I went to the source and it was visible is what i mean when i said i made sure it was there. I probably dont have admissions. my step dad is retarded and changed the password on my admin account.


Discussion

No Comment Found