Hi all,
I am new to vb 2010
I have a assignment where I have a list of 7 friends names. If I type a name in the user input text box and the name is in list box then a message box will appear giving the friends Phone number. IF the friend is not in the list box then a message box will appear stating that person is not in the list.
my problem:
When I run the progrom I have to have the name selected in the list box and type it in the user textbox for it not to set off a error. I need to be able to type the name in the user textbox and if the name is in the list of friends name then it will pop a message box giving the phone number.
Any Help or pointers would be great.
Thanks!!
Here is what I have so for.
Public Class frmPhLookup
Private Sub frmPhLookup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'list of friends names
LstPeople.Items.Add("Joe")
LstPeople.Items.Add("Sam")
LstPeople.Items.Add("Katie")
LstPeople.Items.Add("Erin")
LstPeople.Items.Add("Carmen")
LstPeople.Items.Add("Jessie")
LstPeople.Items.Add("Mark")
End Sub
Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click
'Close the program
Me.Close()
End Sub
Private Sub btFindNubmer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindNumber.Click
'Declerations
Dim Struserinput As String
Dim strPhonenumber() As String = {"555-1212", "123-4532", "234-2134", "232-1234", "123-1234", "555-6789", "454-1235"}
Struserinput = TxtFriend.Text
If Struserinput = LstPeople.SelectedItem Then
MessageBox.Show(strPhonenumber(LstPeople.SelectedIndex))
Else
' if friend is not listed send error message
MessageBox.Show("That friend Is not in the list.")
End If
'Get the phone number for the selected friend
If LstPeople.SelectedIndex > -1 And
LstPeople.SelectedIndex < strPhonenumber.Length Then
MessageBox.Show(strPhonenumber(LstPeople.SelectedIndex))
Else
' if friend is not listed send error message
MessageBox.Show("That friend Is not in the list.")
End If
End Sub
End Class
I am new to vb 2010
I have a assignment where I have a list of 7 friends names. If I type a name in the user input text box and the name is in list box then a message box will appear giving the friends Phone number. IF the friend is not in the list box then a message box will appear stating that person is not in the list.
my problem:
When I run the progrom I have to have the name selected in the list box and type it in the user textbox for it not to set off a error. I need to be able to type the name in the user textbox and if the name is in the list of friends name then it will pop a message box giving the phone number.
Any Help or pointers would be great.
Thanks!!
Here is what I have so for.
Public Class frmPhLookup
Private Sub frmPhLookup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'list of friends names
LstPeople.Items.Add("Joe")
LstPeople.Items.Add("Sam")
LstPeople.Items.Add("Katie")
LstPeople.Items.Add("Erin")
LstPeople.Items.Add("Carmen")
LstPeople.Items.Add("Jessie")
LstPeople.Items.Add("Mark")
End Sub
Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click
'Close the program
Me.Close()
End Sub
Private Sub btFindNubmer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindNumber.Click
'Declerations
Dim Struserinput As String
Dim strPhonenumber() As String = {"555-1212", "123-4532", "234-2134", "232-1234", "123-1234", "555-6789", "454-1235"}
Struserinput = TxtFriend.Text
If Struserinput = LstPeople.SelectedItem Then
MessageBox.Show(strPhonenumber(LstPeople.SelectedIndex))
Else
' if friend is not listed send error message
MessageBox.Show("That friend Is not in the list.")
End If
'Get the phone number for the selected friend
If LstPeople.SelectedIndex > -1 And
LstPeople.SelectedIndex < strPhonenumber.Length Then
MessageBox.Show(strPhonenumber(LstPeople.SelectedIndex))
Else
' if friend is not listed send error message
MessageBox.Show("That friend Is not in the list.")
End If
End Sub
End Class