Essentially what I am trying to do is write a program where you input the person's name and their date of birth, store them to an array (note sure if I have to do two separate arrays) and then by entering their name into another text box and clicking another button I can get the date of birth back.
I know I have to include an if
-loop, I know how to declare an array.
I am guessing that I maybe need to use a select case.
Here is the code:
Public Class Form1
Dim Name(5) As String
Dim DOB(5) As String
Dim i As Integer
Private Sub btnNameEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNameEnter.Click
Name(i) = txtInputName.Text
DOB(i) = txtInputDOB.Text
If i = 6 Then
MsgBox("You cannot enter any more names.")
End If
For i = 1 To 5
Name(i) = i
txtInputName.Clear()
txtInputDOB.Clear()
Next i
End Sub
Private Sub btnFindDOB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindDOB.Click
Select Case Name(i)
Case Is Name(1)
MsgBox("Date of birth: " & DOB(1))
Case is Name(2)
MsgBox("Date of birth: " & DOB(2))
Case is Name(3)
MsgBox("Date of birth: " & DOB(3))
Case is Name(4)
MsgBox("Date of birth: " & DOB(4))
Case is Name(5)
MsgBox("Date of birth: " & DOB(5))
End Select
End Sub
End Class
I would show a picture of the program but visual basic keeps deleting it for some reason and doesn't let me re add the buttons.
Here is an image of the error list: http://gyazo.com/2489a307f4a8e2d9ce65aa2ad79b04f1 )
Public Class Form1 Dim DOB(5) As String Dim i As Integer Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click Dim Name(5) As String
Dim Counter As Integer
txtNameInp.Text = Name(i)
txtDOBInput.Text = DOB(i)
Counter = 0
For i = 1 To 5
If Counter = 6 Then
MsgBox("You can only enter 5 names and DOBs")
End If
Name(i) = txtNameInp.Text
DOB(i) = txtDOBInput.Text
Counter = Counter + 1
Next i
End Sub
Private Sub btnFindDOB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindDOB.Click
Select Case Name(i)
Case Name(1)
MsgBox(DOB(1))
Case Name(2)
MsgBox(DOB(2))
Case Name(3)
MsgBox(DOB(3))
Case Name(4)
MsgBox(DOB(4))
Case Name(5)
MsgBox(DOB(5))
End Select
End Sub
End Class
Here's an error: http://gyazo.com/487290c3e523003fe58f82a15fdf6faa - this one occurs when I try and enter the second number