473,421 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

Why is this generating a message that file is not found

This code works perfectly except when I start I get a message that file is not found. The file is there and everything reads perfectly. How can I get the file to read and not get the message that the file is not found? Do I need to use something other than Try? I tried taking the Try away and then I get errors and no file reads. Jo Ann

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3.         'load the item into the combobox
  4.         Try
  5.  
  6.             vinStreamreader = New StreamReader("car.txt")
  7.             DisplayRecord()
  8.         Catch ex As Exception
  9.             'File is not found.
  10.             MessageBox.Show("File does not exist.")
  11.         End Try
  12.  
  13.  
  14.     End Sub
  15.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  16.         'Read the next record.
  17.         DisplayRecord()
  18.     End Sub
  19.  
  20.     Private Sub DisplayRecord()
  21.         'Read and display the next record.
  22.         Dim vinString As String
  23.         Do While vinStreamreader.Peek <> -1
  24.             vinString = vinStreamreader.ReadLine()
  25.             Me.ComboBox1.Text = vinString
  26.             Me.ComboBox1.Items.Add(ComboBox1.Text)
  27.  
  28.             Me.ListBox1.Items.Add(vinStreamreader.ReadLine())
  29.             Me.ListBox2.Items.Add(vinStreamreader.ReadLine())
  30.             Me.ListBox3.Items.Add(vinStreamreader.ReadLine())
  31.  
  32.         Loop
  33.         'Display labels
  34.         Me.Label4.Text = Me.ListBox1.Items(Me.ComboBox1.SelectedIndex)
  35.         Me.Label5.Text = Me.ListBox2.Items(Me.ComboBox1.SelectedIndex)
  36.         Me.Label6.Text = Me.ListBox3.Items(Me.ComboBox1.SelectedIndex)
  37.  
  38.     End Sub
  39.  
  40.  
  41. End Class
Nov 26 '07 #1
7 1419
Killer42
8,435 Expert 8TB
If the code produces an error, then what do you mean by "working perfectly"?

Presumably it's line 6 that produces the error? If so, then I guess you're looking for the file in the wrong directory. Try specifying the full path to the file.
Nov 26 '07 #2
QVeen72
1,445 Expert 1GB
Hi,

You have hard-coded the message.
Catch the actual Exception message. Change your code this way, and check ..

Expand|Select|Wrap|Line Numbers
  1. Try 
  2.     vinStreamreader = New StreamReader("car.txt")
  3.     DisplayRecord()
  4. Catch ex As Exception
  5.      MessageBox.Show(ex.Message)
  6. End Try
  7.  

Regards
Veena
Nov 26 '07 #3
I did what you said but it just generates another error message that I don't know how to fix. Please advise if you have any ideas how to fix so I don't get an error message.
Nov 26 '07 #4
If the code produces an error, then what do you mean by "working perfectly"?

Presumably it's line 6 that produces the error? If so, then I guess you're looking for the file in the wrong directory. Try specifying the full path to the file.
If I click ok on the message, the program proceeds to run just fine. I just need to get rid of the first error message that pops. The file is there and does not need the full file location to read. I just need the code to get rid of that error message. I tried changing file not found to ex.message but that just generates another error message that I can't fix.
Nov 26 '07 #5
Killer42
8,435 Expert 8TB
... I tried changing file not found to ex.message but that just generates another error message that I can't fix.
I think we need to know the details of the error that is generated.
Nov 26 '07 #6
I think we need to know the details of the error that is generated.

It says "Value cannot be null; Parameter Name: Item
Nov 26 '07 #7
Killer42
8,435 Expert 8TB
It says "Value cannot be null; Parameter Name: Item
Exactly where is it reporting this error? On the New StreamReader? If so, check out the Item parameter, since it apparently needs a value.
Nov 27 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: paul | last post by:
Hi, I'd like to generate PDF files from my Php website. I've found PDFLib to make it... but i'd like to have your views. It is the best I can find ? Are there any other PDF generating lib ?...
3
by: skn | last post by:
Hello., Does the python compiler provide an option to generate a .pyo(optimized byte code file) from a .py (source file)? For generating .pyc I know that I only have to pass the source file...
1
by: Jane | last post by:
Hi I have an .aspx page thats part of a site, its usually called by a user in a browser with an ID in the querystring from where it does lots of exciting things and database reads to produce the...
2
by: V. Jenks | last post by:
I have a C# class that generates a string based on 2 integers. One integer is equal to int.MinValue and the other is equal to int.MaxValue. Each time my class generates a new string from those 2...
8
by: Lars Netzel | last post by:
Hey! I wrote a message yersterday and got some good answers and have now managed to generate a nice image. The problem is that it's all generated in an Images.Aspx file and I don't really want...
9
by: RCS | last post by:
I'm working on an ASP.NET webpage that generates an image (and am using VWD 2005 until my copy of VS2005 ships). I have done all the obvious (and not-so-obvious) things to try to give a gif that I...
2
by: Mike | last post by:
I'm trying to generate a shortcut file from VB. The code below is a cutdown version of some code I found on the net that is supposed to do the job The compiler complains about "WshShell" in the...
9
by: Cesar | last post by:
Hello there, A java programmer sent me a wsdl file, which I have to use to consume his web methods. When I run the wsld.exe tool to generate the class' code, I get the following message: ...
2
by: olympus_mons | last post by:
Hi, I'm just discovering the power of xsd.exe, so maybe I'm doing something wrong. schema files describing requests and responses. So there is an extra xsd file for each response and each...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.