473,397 Members | 1,949 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,397 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 1310
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.