'Variable used to locate the requested title by the user.
Dim strRequestedBook As String = InputBox("Please enter the title of the requested book", "Information Needed")
'This will create an array which will be used to store each line from the textfile into. This will be used to process and find the required book
Dim strResultArray(99) As String
Dim intResultArrayIndex As Integer = 0
While readDetails.Peek() >= 0
strResultArray(intResultArrayIndex) = readDetails.ReadLine()
intResultArrayIndex += 1
End While
readDetails.Close()
Dim intSearchforTitleIndex As Integer = 0
'This loop will then iterate over the array values near the title value and then store those back into the text boxes
Do While intSearchforTitleIndex < strResultArray.Length - 1
If strResultArray(intSearchforTitleIndex) <> strRequestedBook Then
intSearchforTitleIndex += 1
ElseIf intSearchforTitleIndex >= strResultArray.Length - 1 Then
MessageBox.Show("Sorry, that book was not found in that text file. Please try again", "Title not found")
If MsgBoxResult.Cancel Then Return
Else
txtTitle.Text = strResultArray(intSearchforTitleIndex)
txtBookID.Text = strResultArray(intSearchforTitleIndex + 1)
txtAuthorOne.Text = strResultArray(intSearchforTitleIndex + 2)
txtAuthorTwo.Text = strResultArray(intSearchforTitleIndex + 3)
txtAuthorThree.Text = strResultArray(intSearchforTitleIndex + 4)
txtPublisher.Text = strResultArray(intSearchforTitleIndex + 5)
txtYearPublished.Text = strResultArray(intSearchforTitleIndex + 6)
txtBuyingPrice.Text = strResultArray(intSearchforTitleIndex + 7)
txtSellingPrice.Text = strResultArray(intSearchforTitleIndex + 8)
txtCopyNumber.Text = strResultArray(intSearchforTitleIndex + 9)
If strResultArray(intSearchforTitleIndex + 10) = "True" Then
clbGenres.SetItemChecked(0, True)
ElseIf strResultArray(intSearchforTitleIndex + 11) = "True" Then
clbGenres.SetItemChecked(1, True)
ElseIf strResultArray(intSearchforTitleIndex + 12) = "True" Then
clbGenres.SetItemChecked(2, True)
ElseIf strResultArray(intSearchforTitleIndex + 13) = "True" Then
clbGenres.SetItemChecked(3, True)
ElseIf strResultArray(intSearchforTitleIndex + 14) = "True" Then
clbGenres.SetItemChecked(4, True)
ElseIf strResultArray(intSearchforTitleIndex + 15) = "True" Then
clbGenres.SetItemChecked(5, True)
ElseIf strResultArray(intSearchforTitleIndex + 16) = "True" Then
clbGenres.SetItemChecked(6, True)
ElseIf strResultArray(intSearchforTitleIndex + 17) = "True" Then
clbGenres.SetItemChecked(7, True)
ElseIf strResultArray(intSearchforTitleIndex + 18) = "True" Then
clbGenres.SetItemChecked(8, True)
ElseIf strResultArray(intSearchforTitleIndex + 19) = "True" Then
clbGenres.SetItemChecked(9, True)
End If
End If
Loop
End Sub