Ok, so I had this program working, and I don't remember changing anything, but I'm getting the Indexoutofrange exception for Data(1). It says at the bottom that Data only has a length of 1, and even inserting a number into the array doesn't change that. Any ideas?
Public Class frmInventory
Public Structure book
Dim title As String
Dim author As String
Dim category As String
Dim stock As Double
Dim price As Double
End Structure
Dim totalValue As Double
Public books() As book
Private Sub UpdateToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles mnuUpdate.Click
frmDetails.ShowDialog()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles mnuExit.Click
Me.Close()
End Sub
Public Sub frmInventory_load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'open and preload the listbox with books'
Dim bookList() = IO.File.ReadAllLines("books.txt")
Dim num As Integer = bookList.Count - 1
ReDim books(num)
Dim line As String 'holds line for a single book'
Dim Data() As String
For i As Integer = 0 To num
line = bookList(i)
Data = line.Split(","c)
books(i).title = Data(0)
books(i).author = Data(1)
books(i).category = Data(2)
books(i).stock = Data(3)
books(i).price = Data(4)
Next
Dim itemList = From inventory In books
Select inventory.title
Order By title Ascending
For Each title In itemList
lstInventory.Items.Add(title)
Next
End Sub
Public Class frmInventory
Public Structure book
Dim title As String
Dim author As String
Dim category As String
Dim stock As Double
Dim price As Double
End Structure
Dim totalValue As Double
Public books() As book
Private Sub UpdateToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles mnuUpdate.Click
frmDetails.ShowDialog()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles mnuExit.Click
Me.Close()
End Sub
Public Sub frmInventory_load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'open and preload the listbox with books'
Dim bookList() = IO.File.ReadAllLines("books.txt")
Dim num As Integer = bookList.Count - 1
ReDim books(num)
Dim line As String 'holds line for a single book'
Dim Data() As String
For i As Integer = 0 To num
line = bookList(i)
Data = line.Split(","c)
books(i).title = Data(0)
books(i).author = Data(1)
books(i).category = Data(2)
books(i).stock = Data(3)
books(i).price = Data(4)
Next
Dim itemList = From inventory In books
Select inventory.title
Order By title Ascending
For Each title In itemList
lstInventory.Items.Add(title)
Next
End Sub