So the task is: Write a program that contains a text box, a list box and a command button. Put a label above the text box that tells the user to type a number from 1 to 10 inside the text box. When the user clicks the command button, check the text box for a valid number and issue an error message box if the number isn't inside the expected range or in case of empty input. If the user entered a valid number, assign it to the integer variable n and use a For...Next loop to accumulate the sum of the first n elements of an array declared with the statement Dim numList() as Integer = {2, 4, 10, 5, 6, 8, 9, 3, 2, 4} Display the sum in the list box.
Private Sub bCom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bCom.Click
Dim n As Integer = CInt(tNum.Text)
If CDbl(tNum.Text) > 10 Then
MessageBox.Show("Please Enter a Number from 1 to 10")
tNum.Focus()
End If
Dim numList() As Integer = {2, 4, 10, 5, 6, 8, 9, 3, 2, 4}
Dim sum As Integer
For Each n As Integer In numList
sum += n
Next
lOut.Items.Add(sum)
End Sub
End Class