0

I'm trying to get input from a text file to load into a listbox so that I can do more calculations.

I have the math done and all the coding; but when I execute the program it simply won't display the items from the text file into the main list box to chose from.

The program is reading from the text file with streamreader and another app in the program is getting its input but the main list box is empty... Thanks in advance...

Public Class frmDepreciation

'Class level variables
Private _intLifeofItems As Integer = 5
Public Shared _intSizeofArray As Integer = 7
Public Shared _strInventoryItem(_intSizeofArray) As String
Private _strItemId(_intSizeofArray) As String
Private _decInitialPrice(_intSizeofArray) As Decimal
Private _intQuantity(_intSizeofArray) As Integer

Private Sub frmDepreciation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'The frmDepreciation load events reads the inventory text file and
    'fills the listbox object with the inventory items.

    'Initialize an instance of the Streamreader object and declare variables
    Dim objReader As IO.StreamReader
    Dim strLocationandNameofFile As String = "h:\inventory.txt"
    Dim intCount As Integer = 0
    Dim intFill As Integer
    Dim strFileError As String = "The file is not available. Restart when the file is available."

    'Verify the file exists
    If IO.File.Exists(strLocationandNameofFile) Then
        objReader = IO.File.OpenText(strLocationandNameofFile)

        'Read the file line by line until the file is completed
        Do While objReader.Peek <> -1
            _strInventoryItem(intCount) = objReader.ReadLine()
            _strItemId(intCount) = objReader.ReadLine()
            _decInitialPrice(intCount) = Convert.ToDecimal(objReader.ReadLine())
            _intQuantity(intCount) = Convert.ToInt32(objReader.ReadLine())
            intCount += 1
        Loop
        objReader.Close()

        'The lstInventory object is filled with the Inventory IDs
        For intFill = 0 To (_strItemId.Length - 1)
            lstInventoryID.Items.Add(_strItemId(intFill))
        Next

    Else
        MsgBox(strFileError, , "Error")
        Close()
    End If

End Sub
Shawn
  • 9
  • 2
  • 6
  • if you set a breakpoint just before you try to populate the listbox, a) does it stop there, b) if so, does that array contain what you expect? 3 Arrays of related items screams out for a Class which would keep the data together and make it easier to related ID to the underlying data. – Ňɏssa Pøngjǣrdenlarp Sep 01 '14 at 12:21
  • Sorry so long to respond back. Thank you for the breakpoint advice, I had never used that before. I wish I known it was there before. I was making labels to see the info but of course that doesn't always work. Thanks again... – Shawn Oct 04 '14 at 23:26

0 Answers0