Solved

filling multidementional arrays in VB

Posted on 2009-07-08
4
313 Views
Last Modified: 2012-05-07
I have a multidimentional array I want to fill. I'm doing it explicitly:
(see code below)

I was wondering if I could fill each row like this:

        BitRateArray(0) = {32, 32, 32, 32, 8}

Dim BitRateArray(14, 5) As Integer
 

   '32 32 32 32 8 

        BitRateArray(0, 0) = 32

        BitRateArray(0, 1) = 32

        BitRateArray(0, 2) = 32

        BitRateArray(0, 3) = 32

        BitRateArray(0, 4) = 8
 

        '64 48 40 48 16 

        BitRateArray(1, 0) = 64

        BitRateArray(1, 1) = 48

        BitRateArray(1, 2) = 40

        BitRateArray(1, 3) = 48

        BitRateArray(1, 4) = 16
 

        '96 56 48 56 24 

        BitRateArray(2, 0) = 96

        BitRateArray(2, 1) = 56

        BitRateArray(2, 2) = 48

        BitRateArray(2, 3) = 56

        BitRateArray(2, 4) = 24

...

Open in new window

0
Comment
Question by:zliminator
  • 3
4 Comments
 
LVL 20

Expert Comment

by:alainbryden
Comment Utility
Are you working in VB 6 or VB.NET?

--
Alain
0
 
LVL 20

Accepted Solution

by:
alainbryden earned 125 total points
Comment Utility
If you're using VB.net you can use:

--
Alain
Dim BitRateArray(,) As Integer = {{32, 32, 32, 32, 8 }, _

                                  {64, 48, 40, 48, 16},

                                  {96, 56, 48, 56, 24}}

Open in new window

0
 
LVL 20

Expert Comment

by:alainbryden
Comment Utility
After a quick check to be sure, VB6 or earlier doesn't provide any way to declare an array and initialize its elements at the same time. In most cases you end up doing it by setting individual elements as you have.

One way you can create an array of variants on the fly is to go.
Dim varArray() As Variant
varArray() = Array(32, 32, 32, 32, 8)

I'm not sure, but you can probably extend that to go:
Dim varArray() As Variant
varArray() = Array(  Array(32, 32, 32, 32, 8)
                                  Array(64, 48, 40, 48, 16)
                                  Array(96, 56, 48, 56, 24) )
You would then end up referencing elements as varArray(1)(1).

You could also use this in conjunction with a custom function to return an integer array. Details on this method are here http://www.devx.com/vb2themax/Tip/18322, and could probably be adapted to work with a 2D integer array.

Not sure that it gets any better than that with VB6

--
Alain
0
 

Author Closing Comment

by:zliminator
Comment Utility
Thanks, I'm in vb.net but I like both answers. Very helpful, thanks again.

Dan
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 84
allStar challenge 1 41
word0 challenge 4 52
control image tags in a string ? 12 59
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now