Hey guys, how's it going?I'm having a little bit of trouble with Visual Basic.I'm trying to work an array with a variable, you know, like name(i), i having a value that gets set at the beginningBut, to do a For loop to loop for the number of times equal to i, I called up another element, n. n is an integer like iThe lecture slides say it's okay to do this. In fact, here's its example:For i = 1 to num_tracks names(i) = InputBox(“Name of track ” & i) times(i) = InputBox(“Time for track ” & i) total_time = total_time + times(i)Nextnext to my current code for this part: For n = 1 To i 'Get runner's name '==================== name(n) = InputBox("Input runner " & n & "'s name") 'Get a time for each lap '==================== lap1(n) = InputBox("Input the time for " & name(n) & "'s first lap") lap2(n) = InputBox("Input the time for " & name(n) & "'s second lap") NextI run a debug test and it gives me an IndexOutOfRangeException and says "Index was outside the bounds of the array"Here's my full code, btwPublic Class Form1 Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click '==================== 'Coursework 2012 Program 'by Student 09001219 '08/03/2012 '==================== 'Calling elements and arrays '==================== Dim valid As Boolean Dim i As Integer Dim n As Integer Dim name(i) As String Dim lap1(i) As Integer Dim lap2(i) As Integer 'Get valid number of runners '==================== valid = False While valid = False i = InputBox("Input a number between 2 and 8") If i >= 2 Then If i <= 8 Then valid = True End If End If End While 'Loop for number of runners '==================== For n = 1 To i 'Get runner's name '==================== name(n) = InputBox("Input runner " & n & "'s name") 'Get a time for each lap '==================== lap1(n) = InputBox("Input the time for " & name(n) & "'s first lap") lap2(n) = InputBox("Input the time for " & name(n) & "'s second lap") Next MsgBox("This is one of those boxes you get that proves you've got this far without issue") End SubEnd Class
I run a debug test and it gives me an IndexOutOfRangeException and says "Index was outside the bounds of the array"Here's my full code, btwPublic Class Form1 Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click '==================== 'Coursework 2012 Program 'by Student 09001219 '08/03/2012 '==================== 'Calling elements and arrays '==================== Dim valid As Boolean Dim i As Integer Dim n As Integer Dim name(i) As String Dim lap1(i) As Integer Dim lap2(i) As Integer 'Get valid number of runners '==================== valid = False While valid = False i = InputBox("Input a number between 2 and 8") If i >= 2 Then If i <= 8 Then valid = True End If End If End While 'Loop for number of runners '==================== For n = 1 To i 'Get runner's name '==================== name(n) = InputBox("Input runner " & n & "'s name") 'Get a time for each lap '==================== lap1(n) = InputBox("Input the time for " & name(n) & "'s first lap") lap2(n) = InputBox("Input the time for " & name(n) & "'s second lap") Next MsgBox("This is one of those boxes you get that proves you've got this far without issue") End SubEnd Class
March 10th was Mario day, just tought I should let you know.
Quote from: Preytor_4 on March 13, 2012, 04:03:33 PMMarch 10th was Mario day, just tought I should let you know.I'm really happy for you and Imma let you finish, but Bacon has the best day of all time- Bacon Day is the 1st September.
okay i'm having a problem.. every time I try to stream a video on youtube, my computer sh**s itself and lags to all bloody hell..what do ?
Quote from: Preytor_4 on March 13, 2012, 04:03:33 PMMarch 10th was Mario day, just tought I should let you know.i forgot to do the mario!...
also lol at most toxic guy around calling others out on this sh**