create a DuplicateValues application that prompts the user with input boxes for
ID: 3694296 • Letter: C
Question
create a DuplicateValues application that prompts the user with input boxes for numbers between 1 and 99 until duplicate value is entered, the numbers entered before the duplicate value are displayed in a list box and a message in a label displays how many numbers where entered.
This is what I have, I do not know how to get the label to populate the number of numbers added and I am not sure if there should be a loop with the input values button so you don't have to continually click it.
Public Class DuplicateValues
Private Sub btnInput_Click(sender As Object, e As EventArgs) Handles btnInput.Click
Dim x As Integer
Dim y As Integer
x = InputBox("Add number between 0 and 99")
If x < 0 Or x > 99 Then Exit Sub
For y = 0 To lstNumbers.Items.Count - 1
If lstNumbers.Items(y) = x Then lblDuplicate
Next y
lstNumbers.Items.Add(x)
End Sub
End Class
Explanation / Answer
Public Class DuplicateValues
Private Sub btnInput_Click(sender As Object, e As EventArgs) Handles btnInput.Click
Dim x As Integer
Dim y As Integer
Dim a[100] As Array
x = InputBox("Add number between 0 and 99")
If x < 0 Or x > 99 Then Exit Sub
For y = 0 To lstNumbers.Items.Count – 1
If lstNumbers.Items(y) = x Then lblDuplicate
else
a[y] = x
do
label.Text = lstNumbers.Items.Count()
Loop until lstNumbers.Items(y) = x
MessageBox.Show(“Dupilcate”, & lstNumbers.Items(y))
MessageBox.Show(“List of Numbers: “, & lstNumbers.Items)
lstNumbers.Items.Add(a[y])
Next y
MessageBox.Show(a[])
MessageBox.Show(label.Text)
End Sub
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.