?
Solved

help: add row to 2D jagged array

Posted on 2003-03-04
9
Medium Priority
?
725 Views
Last Modified: 2008-02-01
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"
0
Comment
Question by:dbyrne03
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 2

Expert Comment

by:Jacamar
ID: 8068766


Redim Preserve student(1 to blah, 1 to blah)
0
 

Author Comment

by:dbyrne03
ID: 8068938
what would be the value of 'blah' if I were to add one row to the array?
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8069051
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dbyrne03
ID: 8069072
I can't get to a compiler until tomorrow but I think this'll do it.
0
 

Author Comment

by:dbyrne03
ID: 8082945
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.
0
 

Author Comment

by:dbyrne03
ID: 8082961
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?
0
 

Author Comment

by:dbyrne03
ID: 8083106
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?
0
 

Author Comment

by:dbyrne03
ID: 8083120
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() {""}
0
 
LVL 2

Accepted Solution

by:
Jacamar earned 130 total points
ID: 8083471
Cool.  I'm glad you solved.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question