Hello guys,
I am working on this code and its supposed to read information from a text file located in the debug folder and then populate a list box from it. For some reason its not loading the items. I verified the array and it contains the items. This is the code I am using:
The file contains the following information:
12AVX
5
23ABC
8.97
23TWT
4.69
34ZAB
12.5
91BAN
34.67
Thanks a lot for the help.
PS: Its a school exercise but not homework.
I am working on this code and its supposed to read information from a text file located in the debug folder and then populate a list box from it. For some reason its not loading the items. I verified the array and it contains the items. This is the code I am using:
Code:
Public Class frmMain
Structure Product
Dim Item As String
Dim price As Double
End Structure
Private Products(5) As Product
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim inFile As IO.StreamReader
Const strFILE_NAME As String = "ItemInfo.txt"
'check if the file exits
If IO.File.Exists(strFILE_NAME) Then
' open the file
inFile = IO.File.OpenText(strFILE_NAME)
' fill the array
For intSub As Integer = 0 To 4
Products(intSub).Item = inFile.ReadLine
Products(intSub).price = CDbl(inFile.ReadLine)
Next intSub
' Close the file
inFile.Close()
' Fill the listBox
For intIndex As Integer = 0 To UBound(Products) '<====== if it type "Step 2" here it works but loads items 1,3,5
lstNumbers.Items.Add(Products(intIndex).Item)
Next intIndex
Else
MessageBox.Show("The file ItemInfo.txt does not exist", "Missing File",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
End Class12AVX
5
23ABC
8.97
23TWT
4.69
34ZAB
12.5
91BAN
34.67
Thanks a lot for the help.
PS: Its a school exercise but not homework.