473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

best way to Dim arrays you don't know the size of?

If you don't know the size of an array when you create it (and it
needs to be available to the whole program), is it more efficient to
use redim or (,) e.g. :

1.

Public class form1
….
Dim SampleArray(,) as string


Private sub Something()
Dim NowWeKnowTheValueOfTheArray as integer = 100
Dim NowWeKnowTheValueOfTheArray2 as integer = 1000

For i = 0 to NowWeKnowTheValueOfTheArray - 1
For j = 0 to NowWeKnowTheValueOfTheArray2 - 1
SampleArray(i, j) = "Something"
next
Next

Or

2.

Public class form1
…..
Dim SampleArray(0,1) as string
…..

Private sub Something()
Dim NowWeKnowTheValueOfTheArray as integer = 100
Dim NowWeKnowTheValueOfTheArray2 as integer = 1000

Redim SampleArray(NowWeKnowTheValueOfTheArray - 1 ,
NowWeKnowTheValueOfTheArray2 - 1)

For i = 0 to NowWeKnowTheValueOfTheArray - 1
For j = 0 to NowWeKnowTheValueOfTheArray2 - 1
SampleArray(i, j) = "Something"
next
Next

Or something else?
Nov 20 '05 #1
1 1303
"Scott M" <sc**********@tiscali.co.uk> schrieb
If you don't know the size of an array when you create it (and it
needs to be available to the whole program), is it more efficient
to use redim or (,) e.g. :

1.

Public class form1
….
Dim SampleArray(,) as string


Private sub Something()
Dim NowWeKnowTheValueOfTheArray as integer = 100
Dim NowWeKnowTheValueOfTheArray2 as integer = 1000

For i = 0 to NowWeKnowTheValueOfTheArray - 1
For j = 0 to NowWeKnowTheValueOfTheArray2 - 1
SampleArray(i, j) = "Something"
next
Next

Or

2.

Public class form1
…..
Dim SampleArray(0,1) as string
…..

Private sub Something()
Dim NowWeKnowTheValueOfTheArray as integer = 100
Dim NowWeKnowTheValueOfTheArray2 as integer = 1000

Redim SampleArray(NowWeKnowTheValueOfTheArray - 1 ,
NowWeKnowTheValueOfTheArray2 - 1)

For i = 0 to NowWeKnowTheValueOfTheArray - 1
For j = 0 to NowWeKnowTheValueOfTheArray2 - 1
SampleArray(i, j) = "Something"
next
Next

Or something else?

Use Dim to specify the dimension (rank) of the array (2-dimensional in this
case) only. Use Redim to create the array:

…..
Dim SampleArray(,) as string
…..

Private sub Something()
Dim NowWeKnowTheValueOfTheArray as integer = 100
Dim NowWeKnowTheValueOfTheArray2 as integer = 1000

Redim SampleArray(NowWeKnowTheValueOfTheArray - 1 ,
NowWeKnowTheValueOfTheArray2 - 1)

For i = 0 to NowWeKnowTheValueOfTheArray - 1
For j = 0 to NowWeKnowTheValueOfTheArray2 - 1
SampleArray(i, j) = "Something"
next
Next
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: - Steve - | last post by:
For a school assignment I need to write a class to work with the following code. The IntArray b(-3, 6) basically means that I need to produce an array of integer values that has an index going...
1
by: Scott M | last post by:
If you don't know the size of an array when you create it (and it needs to be available to the whole program), is it more efficient to redim or use (,) e.g. : 1. Public class form1 …. Dim...
19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
5
by: Cant Think Today | last post by:
I have multi-dimesional arrays that can be specifed by the user, e.g 1,2,3,4,5 1,2,3,4,5,6,7,8,9,10 1,2,3,4,5,6 I think a bit of code that will iterate over these arrays to print out the...
13
by: Ben | last post by:
I have a program which is using a lot of memory. At the moment I store a lot of pointers to objects in std::vector. (millions of them) I have three questions: 1) Lets say the average Vector...
2
by: hokieghal99 | last post by:
I wish to place all files and directories that are within a user defined path (on a Linux x86 PC) into some type of array and then examine those items for the existence of certain charaters such as...
8
by: masood.iqbal | last post by:
All this time I was under the illusion that I understand the concept of multi-dimensional arrays well ---- however the following code snippet belies my understanding. I had assumed all along...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
5
by: Gomaw Beoyr | last post by:
Hello Is there any explanation why Microsoft chose to implement arrays as objects allocated on the heap instead of structs allocated on the stack? For "mathematical stuff", one normally...
4
by: Edward Jensen | last post by:
Hi, I have the following static arrays of different size in a class: in header: static double w2, x2; static double w3, x3; static double w4, x4; in GaussLegendre.cpp:
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.