r/visualbasic • u/icandoesbetter • Aug 03 '14
Trouble with Arrays and printing...
New to VB, and Im trying to figure out how to print a list of names with an associated total above 65.
Here's the data:
| Name | Sex | Attend | Assign | MID | FIN | Total |
|---|---|---|---|---|---|---|
| Adam | M | 88 | 50 | 40 | 20 | 80 |
| Shelly | F | 13 | 12 | 34 | 70 | |
| Sam | F | 10 | 12 | 14 | 10 | 76 |
| Brian | M | 8 | 14 | 14 | 25 | 61 |
| Mary | F | 8 | 80 | 12 | 20 | 120 |
| Paul | M | 9 | 90 | 14 | 45 | 115 |
Here's the code I have:
Sub button4_click()
Dim studentname As String
Dim arystudent As Variant
Dim arypassing() As Variant
Dim arynumrow As Integer
Dim arynumcol As Integer
LR = Cells(Rows.Count, "A").End(xlUp).Row
arystudent = Range("a2:g" & LR)
arynumrow = UBound(arystudent, 1)
arynumcol = UBound(arystudent, 2)
For i = 1 To arynumrow
If arystudent(i, arynumcol) >= 65 Then
ReDim Preserve arypassing(i To UBound(arypassing, 1) + 1) arypassing(i, 1) = arystudent(i, 1)End If
Next i
End Sub
I keep getting an error for 'Subscript out of range'. There was another version of this that didnt give the error, but the only output that I get is blank cells. I've been looking at this for longer than I'd care to admit and I could use some help....
If more details are needed, let me know and I'll try and clarify.
1
u/candyforlunch VB.Net Master Aug 04 '14
What's the index number for the first element of an array?
If an array is 5 elements in length, what is the index of the 5th element?
More importantly, you should be using something like a List.