Does anyone see anything wrong w/ this Do Loop.

i am trying to read a .ini(text file) in a listbox. i know that in order for the listbox to display the text (not on one line) that i need to write a loop. Here's my code:

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
Dim objStreamReader As StreamReader
Dim strLine As String

If RadioButton2.Checked = True Then
objStreamReader = New StreamReader("C:Documents and SettingsVB PROJECTS estfile.ini")

Do While Not strLine Is Nothing
strLine = objStreamReader.ReadLine()
ListBox1.Items.Add(strLine)
Loop
objStreamReader.Close()
End If

End Sub

i don't get any error messages, but the text file does not display in the listbox. What did i do wrong?

Comments

  • Nevermind. I figured it out.

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
    Dim objStreamReader As StreamReader
    Dim StrLine As String


    If RadioButton2.Checked = True Then
    ListBox1.Items.Clear() ' this clears it!
    objStreamReader = New StreamReader("C:Documents and SettingsVB PROJECTSpntcreedt.ini")
    StrLine = objStreamReader.ReadLine
    Do While Not StrLine Is Nothing
    ListBox1.Items.Add(StrLine)
    StrLine = objStreamReader.ReadLine()
    Loop

    End If
    End Sub


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion