VB.Net: I am using two forms - frmDetails, frmInventory frmInventory contains a list box that reads a text file containing a list of book title, author, category, # in stock, and price per item (five elements). The list box displays only the book titles.
frmDetails contains individual text boxes that match the elements in the text file.
If a user selects one of the items (titles) in the frmInventory list box and chooses update from a drop-down menu, the text boxes in frmDetails need to be populated with the elements that match their label (title with title, author with author, etc.). In other words, after selected, the text file needs to be read, the data parsed, and populated in each text box.
I have tried a few different forms of code:
Dim selectedUpdate As String = lstBookList.SelectedItem.ToString
If selectedUpdate = lstBookList.SelectedItem.ToString Then
Dim queryUpdate = From item In File.ReadAllLines("Books.txt")
Let ti = item.Split(","c)(0)
Let au = item.Split(","c)(1)
Let ca = item.Split(","c)(2)
Let qt = item.Split(","c)(3)
Let co = item.Split(","c)(4)
Where ti = selectedUpdate
Select ti & "," & au & "," & ca & "," & qt & "," & co
For Each ti In queryUpdate
frmDetails.txtTitle.Text = ti
For Each au In queryUpdate
frmDetails.txtAuthor.Text = au
For Each qt In queryUpdate
frmDetails.txtStock.Text = qt
For Each co In queryUpdate
frmDetails.txtPrice.Text = co
Next
Next
Next
Next
End If
frmDetails.ShowDialog()
End Sub
Or:
Dim selectedUpdate As String = lstBookList.SelectedItem.ToString
Dim itemToUpdate() As String = File.ReadAllLines("Books.txt")
If selectedUpdate = lstBookList.SelectedItem.ToString Then
Dim queryTitle = From bookTitle In itemToUpdate
Let ti = bookTitle.Split(","c)(0)
Where ti = selectedUpdate
Select ti
For Each ti In queryTitle
frmDetails.txtTitle.Text = ti
Next
Dim queryAuthor = From bookAuthor In itemToUpdate
Let au = bookAuthor.Split(","c)(1)
Where au = selectedUpdate
Select au
For Each au In queryAuthor
frmDetails.txtAuthor.Text = au
Next
Or:
Dim selectedUpdate As String = lstBookList.SelectedItem.ToString
Dim itemToUpdate() As String = File.ReadAllLines("Books.txt")
If selectedUpdate = lstBookList.SelectedItem.ToString Then
Dim queryUpdate = From item In File.ReadAllLines("Books.txt")
Let ti = item.Split(","c)(0)
Let au = item.Split(","c)(1)
Let ca = item.Split(","c)(2)
Let qt = item.Split(","c)(3)
Let co = item.Split(","c)(4)
Where ti = selectedUpdate
Select ti, au, ca, qt, co
frmDetails.txtTitle.Text = (queryUpdate.ToString) ti
frmDetails.txtAuthor.Text = au
frmDetails.txtStock.Text = qt
The problem is with parsing the data in the record so that it can be dispersed into the different text fields.
Any assistance would be appreciated.