be58d2003 Posted January 8, 2004 Posted January 8, 2004 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim A As Integer, B As String, FileName As String = "C:\Program Files\TTools202\Aircraft030528.txt" Dim OpenFile As FileStream = New FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read) Dim SR As StreamReader = New StreamReader(OpenFile) A = A + 1 If A >= 1 Then Timer1.Enabled = False Do B = SR.ReadLine ComboBox1.Items.AddRange(New Object() {B}) Loop Until B Is Nothing SR.Close() OpenFile.Close() End If ComboBox1.Enabled = True End Sub Ok, I must be stupid or something... Can someone please help?! I want to read a .txt file, and have the items listed (line by line) in the DropDown list... The previous code is what I am trying... However, I get an unhandled exception error saying that the value can not be null and parameter name: item. I tested it by clicking "Continue" in the error box. I shows the dropdown list with all of the contents of the .txt file. So what is causing this error? Quote Firefighters do it with a big hose...
Administrators PlausiblyDamp Posted January 8, 2004 Administrators Posted January 8, 2004 change the middle bit to Do B = SR.ReadLine If Not B Is Nothing Then ComboBox1.Items.AddRange(New Object() {B}) end if Loop Until B Is Nothing the last SR.ReadLine will be nothing - thats what is causing the error. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
be58d2003 Posted January 8, 2004 Author Posted January 8, 2004 Thanks, I will give it a try. Quote Firefighters do it with a big hose...
be58d2003 Posted January 8, 2004 Author Posted January 8, 2004 Thank You so much, fixed the problem. Quote Firefighters do it with a big hose...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.