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