Hi i am trying to do this project for class and i have been stuck on it for a couple of days
Here is the assignment
Write a program that allows the user to enter up to 20 Pro team names and then displays them. The user doesn’t have to enter 20 but they may not enter more than 20.
The team names must be stored in an array.
A For…..Next loop must be used to display the team names in a listbox.
If the user attempts to enter more than 20 team names an error should be displayed “No space to record additional team name”
The .clear and .focus features should be used to clear and reset the textbox after the record button is clicked.
The array and the counter used as the index for the array should be declared globally.**
Here is my code
Public Class Form1 Dim named(19) As String Dim cnt As Integer = 0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click named(cnt) = TextBox1.Text cnt = cnt + 1 TextBox1.Text = Nothing End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim strcnt As Integer = 0 Label2.Text = cnt If cnt <= 20 Then For strcnt = 0 To named.Length - 1 ListBox1.Items.Add(named(strcnt)) Next Else ListBox1.Items.Add("No space to record additional team name") End If End Sub
So in button 1 (the Record team name button) i set the array named(cnt) = textbox1.text.. CNT is the counter. Then add 1 to cnt for the next time the button is clicked. It will set named(1) = to the value in textbox1. Then clear the textbox1.text
In button 2 (display button) i create a new variable called STRCNT, which is a other counter for the for next loop! Ok i then set label2 = to cnt.. (This will display the number of teams). I then use a for next loop to check if cnt is less then 20 or greater then 20. I then use a for next loop to display all values in named in the listbox (IF it is less then 20!!) If it is greater i display the text in the listbox "No space to record additional team name"...
ALSO i havent done the reset button yet, plan to do that at the end.
So when i run the program it works fine when i enter names, but when i click the display button it highlights the code "ListBox1.Items.Add(named(strcnt))"
It says "Value cannot be null.Parameter name: item"
Can anyone please help!!!