Question: I need help regarding my Visual Basic lab Can you please find my mistake why must button(Search for item is not working). so in the
I need help regarding my Visual Basic lab Can you please find my mistake why must button(Search for item is not working). so in the program Search by Item Description button click event This event validates that information does exist in the input list box (IstCollectables) and that the user has entered a description in the Item textbox (txt/item). If the input is valid, the input listbox (lstCollectables) is search to see if a record with a matching description exists in the list. If it does, the value of the item should be displayed in the value textbox (txtValue). If no match is found, the user should be given a message letting them know that no match was found.
Public Class Frmlabreview
Private Sub a_Click(sender As Object, e As EventArgs) Handles a.Click
Dim item As String
Dim value As Decimal
Do
item = CStr(InputBox("Enter item description or -1 to stop "))
If item "-1" Then
value = InputBox("Enter the value of a item:")
lstCollectable.Items.Add(item & "," & value)
End If
Loop Until item = "-1"
End Sub
Function DataExist() As Boolean
If lstCollectable.Items.Count
MessageBox.Show("The event required the information on the list box")
lstCollectable.Focus()
Return False
End If
Return True
End Function
Function ItemOk() As Boolean
If txtitem.Text = "" Then
MessageBox.Show("The event required you to enter the item in the text box")
txtitem.Focus()
Return False
End If
Return True
End Function
Function ValueOk() As Boolean
If txtvalue.Text = "" And (IsNumeric(txtvalue.Text)) Then
MessageBox.Show("The event required you to enter valid value")
Return False
End If
Return True
End Function
Sub GetIteam(ByRef item As String)
item = txtitem.Text
End Sub
Sub GetValue(ByVal value As Decimal)
value = txtvalue.Text
End Sub
Sub DissectLine(ByVal line As String, ByRef item As String, ByVal value As Decimal)
Dim comma As String
comma = line.IndexOf(",")
item = line.Substring(0, comma)
value = line.Substring(comma + 1).Trim
End Sub
Private Sub btnserchitem_Click(sender As Object, e As EventArgs) Handles btnserchitem.Click
If DataExist() = False Then
Return
End If
Dim item As String
Dim value As Decimal
Dim line As String
Dim found As Boolean = False
Dim SearchItem As String
GetIteam(item)
GetValue(value)
SearchItem = item
For i As Integer = 0 To lstCollectable.Items.Count - 1
line = CStr(lstCollectable.Items(i))
DissectLine(line, item, value)
If item = SearchItem Then
found = True
Exit For
End If
Next
If found = True Then
txtvalue.Text = value
End If
End Sub
End Class
Working with ListBoxes IstCollectable Populate Collectable Search For Item Search For Value Search for Value Item: Value: Istdisplay Clear Form Exit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
