473,385 Members | 1,185 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,385 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
redim or use (,) 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?
Jul 21 '05 #1
1 1307
It is best to use an ArrayList object that can grow as you need it.

You can set an initial size.

--- Nick

"Scott M" <sc**********@tiscali.co.uk> wrote in message
news:ea*************************@posting.google.co m...
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 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?

Jul 21 '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...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.