Hello again,

How do i do the code where i have a list box with certain names in. Also a textbox called Username.

When someone enters the name into the textbox to get access to a form, how do i make it so it only allows the names from that listbox. Ie. in the list box it has Joe Bloggs and Joanna Bloggs. In the textbox i write Joe Bloggs to get in. if i write something different thats not in the listbox it then opens a messagebox and doesnt allow me access.


you can use an if statement to compare the input in the textbox against the value in the list box , and a for loop to shift from one index to another in the list box.


Try something like this

Private Sub FindMySpecificString(ByVal searchString As String)
   ' Ensure we have a proper string to search for.'
   If searchString <> String.Empty Then

       Dim index As Integer = listBox1.FindStringExact(searchString)
       ' Determine if a valid index is returned. Select the item if it is valid.'
       If index <> ListBox.NoMatches Then
          ListBox1.SetSelected(index, True)
          MsgBox("Got it")
          MsgBox("The search string did not find any items in the ListBox")
          TextBox4.Text = "" 'the textbox u require
       End If
   End If
End Sub

call this function in the button click event

What sort of If statement could i do? i tried

if textbox4.text = listbox1.items = false then
msgbox("Enter Correct Username")

I know its wrong. What code do you suggest i use and what loop do i use?


This article has been dead for over six months. Start a new discussion instead.