Adding Items To A ComboBox Via File Reading?!

be58d2003

Well-known member
Joined
Mar 23, 2003
Messages
81
Location
Antioch, California
Code:
 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?
 
change the middle bit to
Code:
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.
 
Back
Top