Hi,
I'm very new to VB and I'm completing a small program uses a listbox. What has me totally stumped. I want to be able to:
Below is my code so far but I am getting exception errors:
Any help would be great. apologies if i have posted incorrectly!
Sam
I'm very new to VB and I'm completing a small program uses a listbox. What has me totally stumped. I want to be able to:
- enter a string into a textbox
- when executed checks the string is not already added to the listbox
- if the string already exists = error message
- if it does not exist - add it to the list box.
Below is my code so far but I am getting exception errors:
VB.NET:
Private Sub AddTextBoxButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddTextBoxButton.Click
Dim vSearchValue As String
vSearchValue = ValueTextBox.Text
SearchList(vSearchValue)
End Sub
Function SearchList(ByVal vSearchValue As String) As Boolean
Dim vIndex As Integer
Dim vFoundMatch As Boolean = False
For vIndex = 0 To ValueListBox.Items.Count - 1
If ValueListBox.Items(vIndex) = vSearchValue Then
vFoundMatch = True
Exit For
End If
Next
If vFoundMatch = False Then
ValueListBox.Items.Add(vFoundMatch)
Else
MessageBox.Show("Subject Code already in the list")
End If
End Function
Any help would be great. apologies if i have posted incorrectly!
Sam