Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Declaring Multi-Dimensional Jagged Array in VB.NET
Author:
Chris
E-mail:
Click to e-mail author
Website:
http://www.visualbasictutorial.net
Submitted:
10/24/2013
Version:
VB 2010
Compatibility:
VB 2005, VB 2008, VB 2010, VB 2012
Category:
Miscellaneous
Views:
6243
A virtually undocumented feature, Jagged Arrays are a great resource for storing arrays of uneven length. This code snippet shows you how to declare and loop through such a structure.
Declarations:
'My books Dim myBooks(1, 1) As String 'Harry’s books Dim harrysBooks(3, 1) As String Dim jaggedArray()(,) As String = New String(1)(,) {}
Code:
'Store my books myBooks(0, 0) = "Microsoft Visual Basic 2010 Step By Step" myBooks(0, 1) = "Michael Halvorson" myBooks(1, 0) = "Sams Teach Yourself Visual Basic 2012 in 24 Hours" myBooks(1, 1) = "James Foxal" 'Store Harry's books harrysBooks(0, 0) = "Excel VBA Programming For Dummies" harrysBooks(0, 1) = "John Walkenbach" harrysBooks(1, 0) = "Sams Teach Yourself Visual Basic 2012 in 24 Hours" harrysBooks(1, 1) = "James Foxal" harrysBooks(2, 0) = "Learn to Program with Visual Basic" harrysBooks(2, 1) = "John Smiley" harrysBooks(3, 0) = "Distributed Applications with Microsoft Visual Basic 6.0" harrysBooks(3, 1) = "Microsoft" jaggedArray(0) = myBooks jaggedArray(1) = harrysBooks 'loop through the arrays stored in the jagged array For i As Integer = 0 To jaggedArray.GetUpperBound(0) 'loop through the rows in the arrays For j As Integer = 0 To jaggedArray(i).GetUpperBound(0) 'loop the columns For k = 0 To jaggedArray(i).GetUpperBound(1) Debug.Print jaggedArray(i)(j, k) Next Next Next
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement