Link to home
Start Free TrialLog in
Avatar of dbyrne03
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"
Avatar of Jacamar
Jacamar



Redim Preserve student(1 to blah, 1 to blah)
Avatar of dbyrne03

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.
I can't get to a compiler until tomorrow but I think this'll do it.
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.
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?
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?
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() {""}
ASKER CERTIFIED SOLUTION
Avatar of Jacamar
Jacamar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial