dbyrne03
asked on
help: add row to 2D jagged array
I am writing in VB.net, using VS.net . I've used the following syntax to declare a 2D jagged array with no rows:
Dim students As student()() = New student()() {}
Is this correct? Now when a new student must be added to the array, I must "add a row". How do I do this? I am pretty sure I must start with "Redim Preserve"
Dim students As student()() = New student()() {}
Is this correct? Now when a new student must be added to the array, I must "add a row". How do I do this? I am pretty sure I must start with "Redim Preserve"
ASKER
what would be the value of 'blah' if I were to add one row to the array?
ok, use a value like say
inRows
that will keep track of your rows. Your statement would be
inRows = inRows + 1
redim preserve student(1 to inRows, 1 to inColumns)
sorry about the unclearity, I don't know why I did that.
inRows
that will keep track of your rows. Your statement would be
inRows = inRows + 1
redim preserve student(1 to inRows, 1 to inColumns)
sorry about the unclearity, I don't know why I did that.
ASKER
I can't get to a compiler until tomorrow but I think this'll do it.
ASKER
when doing the above, the "to" in the parentheses has a jagged blue underline. Hovering the cursor over this line reads "Comma, ')' or a valid expression continuation is expected". I've been poking arounf and VS.net seems to only accept integer values within either set of parentheses.
ASKER
also, it appears as though the above would be used to redifine a rectangular array, as you have one set of parentheses. Wouldn't I need two pairs, since this is a jagged array?
ASKER
also, it appears as though the above would be used to redifine a rectangular array, as you have one set of parentheses. Wouldn't I need two pairs, since this is a jagged array?
ASKER
actually, here's what worked:
' create jagged two-dimensional array
Dim myarray As String()()
'adds a row to the jagged array
Dim rowtotal As Integer
rowtotal = myarray.GetUpperBound(0) + 1
ReDim Preserve myarray(rowtotal)
myarray(rowtotal) = New String() {""}
' create jagged two-dimensional array
Dim myarray As String()()
'adds a row to the jagged array
Dim rowtotal As Integer
rowtotal = myarray.GetUpperBound(0) + 1
ReDim Preserve myarray(rowtotal)
myarray(rowtotal) = New String() {""}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Redim Preserve student(1 to blah, 1 to blah)