• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[VB2010] Module, Lixtbox loops

It won't fit
Loyal Member
Joined
May 18, 2007
Messages
1,789
Reaction score
291
I have a problem with the below. It keeps looping, I know why, but what I don't know is why it's not inserting the info into the listbox. It doesn't throw any errors either. Everything is set from Private to Public, no effect. I had this problem before but I can't remember how I fixed it for the life of me. Even then, it was in C#.

Code:
Public Function LoadItemLibrary(ByVal path As String)
        Try
            Dim ItemReader As StreamReader = New StreamReader(path)
            AceTool.ItemList.Items.Clear()
            Do
     Loops here   --->  AceTool.ItemList.Items.Add(ItemReader.ReadLine)
     Loops here   --->  AceTool.ListBox1.Items.Add(ItemReader.ReadLine)
            Loop Until ItemReader.Peek = -1
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
            If AceTool.ItemList.Items.Count > 0 Then
                AceTool.ItemList.Enabled = True
            Else
                AceTool.ItemList.Items.Add("Error reading library")
            End If
        End Try
    End Function
 
Newbie Spellweaver
Joined
Jul 21, 2010
Messages
39
Reaction score
0
Apply this methodology to check for proper output of the StreamReader, see for details. Here is an excerpt from MSDN.

Code:
Imports System
Imports System.IO

Class Test
    Public Shared Sub Main()
        Try
            ' Create an instance of StreamReader to read from a file.
            Dim sr As StreamReader = New StreamReader("TestFile.txt")
            Dim line As String
            ' Read and display the lines from the file until the end 
            ' of the file is reached.
            Do
                line = sr.ReadLine()
                Console.WriteLine(Line)
            Loop Until line Is Nothing
            sr.Close()
        Catch E As Exception
            ' Let the user know what went wrong.
            Console.WriteLine("The file could not be read:")
            Console.WriteLine(E.Message)
        End Try
    End Sub
End Class
 
WowIwasSuperCringeB4
Loyal Member
Joined
Jun 21, 2008
Messages
1,297
Reaction score
226
Separate the strings, I'm not sure how to do it in VB but in C# you do Foreach(string lines in sr.ReadLine())
{
//Do what ever here.
}
 
It won't fit
Loyal Member
Joined
May 18, 2007
Messages
1,789
Reaction score
291
It didn't work. It's something simple. But I just can't remember what :/

I had it in the original form class, but I moved it to a different module class, that's when it stopped working.
 
Back
Top