I'm currently taking a VB class in school and had to design a program that takes a .txt file and reads it line by line to display the fields that make up an employee record on a form for the user to view. We had to previously write a program that wrote the data to the file and this program is only supposed to be capable of retrieving and displaying the data from the file.
When the form is loading, the application asks the user for the name of the file the application is to work with via input box, stores the value to a string variable (strFilename) and appends \ at the start and .txt at the end, and is supposed to display the first record (or first 8 lines in the file) in the appropriate labels on the form corresponding to the field names. With this in mind, it checks the root of the device the project is read from and doesn't require the user to enter .txt (only the filename). If the file doesn't exist, it displays an error message and than terminates the application.
The problem I'm having here is with the IO.File.Exists method. I get the input from the user and use an if statement to make sure it exists. If its true, it runs the rest of the code and else it is supposed to terminate as described above. Here is an example of how its setup:
I use test.txt and though the if condition should be true, I step through the code one line at a time to discover it gets to the if statement and than immediately goes to Else and executes the code in there though test.txt is valid.
All code is correct from what my instructor and myself could see (he went ahead and gave me the grade for it, thinking that VS appended another .txt to the end of it automatically, making it impossible to fix). The application runs fine on my laptop but not in the lab (We haft to present our applications before they are accepted to ensure they are working).
I think it has to do with perhaps one of the many hundreds of settings Visual Studio has. Or maybe the inital enviornment configuration? My setup at home is general but the setup in the lab is setup specifically for VB. Any one know of what setting (if one) could be causing this type of behavior to occur or know of a workaround? I'm using VS 2008.
When the form is loading, the application asks the user for the name of the file the application is to work with via input box, stores the value to a string variable (strFilename) and appends \ at the start and .txt at the end, and is supposed to display the first record (or first 8 lines in the file) in the appropriate labels on the form corresponding to the field names. With this in mind, it checks the root of the device the project is read from and doesn't require the user to enter .txt (only the filename). If the file doesn't exist, it displays an error message and than terminates the application.
The problem I'm having here is with the IO.File.Exists method. I get the input from the user and use an if statement to make sure it exists. If its true, it runs the rest of the code and else it is supposed to terminate as described above. Here is an example of how its setup:
Code:
if IO.File.Exists(strFileName) Then
[INDENT]'Runs the rest of the startup routine as the file exists
[/INDENT]Else
[INDENT]'Terminate the application after displaying an error
[/INDENT]End If
I use test.txt and though the if condition should be true, I step through the code one line at a time to discover it gets to the if statement and than immediately goes to Else and executes the code in there though test.txt is valid.
All code is correct from what my instructor and myself could see (he went ahead and gave me the grade for it, thinking that VS appended another .txt to the end of it automatically, making it impossible to fix). The application runs fine on my laptop but not in the lab (We haft to present our applications before they are accepted to ensure they are working).
I think it has to do with perhaps one of the many hundreds of settings Visual Studio has. Or maybe the inital enviornment configuration? My setup at home is general but the setup in the lab is setup specifically for VB. Any one know of what setting (if one) could be causing this type of behavior to occur or know of a workaround? I'm using VS 2008.