473,395 Members | 1,442 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,395 software developers and data experts.

Creating an array with an unknown number of values?

I'm trying to create an array with a size I don't know.

For instance:

Dim values() As Integer
Dim valuesString As String = ""
while something
valuesString = valuesString & newValue 7 ", "
end while
....trim off last ", "...
values = new integer() {valuesString}

However, in attempting to put the valuesString into the array, I get this
error:

System.FormatException: Input string was not in a correct format.

So, it looks like I can't put a comma-delimited string in as the values for
an array. As such, how should I approach this?

I went ahead and made two WHILE loops...the first to simply count the number
of items I need, then dim the array with a specific size, then do another
while loop to populate each of the values. Is there a more elegant way?

-Darrel

--
================================================== ===============
Win prizes searching google:
http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA
Mar 29 '06 #1
3 1853
Why not use a List or Collection? That is what they are for.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"darrel" <no*****@nowhere.com> wrote in message
news:e$**************@TK2MSFTNGP11.phx.gbl...
I'm trying to create an array with a size I don't know.

For instance:

Dim values() As Integer
Dim valuesString As String = ""
while something
valuesString = valuesString & newValue 7 ", "
end while
...trim off last ", "...
values = new integer() {valuesString}

However, in attempting to put the valuesString into the array, I get this
error:

System.FormatException: Input string was not in a correct format.

So, it looks like I can't put a comma-delimited string in as the values
for an array. As such, how should I approach this?

I went ahead and made two WHILE loops...the first to simply count the
number of items I need, then dim the array with a specific size, then do
another while loop to populate each of the values. Is there a more elegant
way?

-Darrel

--
================================================== ===============
Win prizes searching google:
http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA

Mar 29 '06 #2
> Why not use a List or Collection? That is what they are for.

Well, I read an arrayList has a lot more overhead. But if that's what it's
for, then that's probably what I should use. ;o)

-Darrel
Mar 29 '06 #3
Hi darrel,

An ArrayList initially takes up more memory than an array. However, resizing
an array means making a whole new array. I'm sure you can see how a few
resizes would tip the balance in favor of a Collection or List.

It's a good thing, though, that you're paying attention to optimization
issues!

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"darrel" <no*****@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Why not use a List or Collection? That is what they are for.


Well, I read an arrayList has a lot more overhead. But if that's what it's
for, then that's probably what I should use. ;o)

-Darrel

Mar 30 '06 #4

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

Similar topics

3
by: zimba | last post by:
Hello, Do you know a better way to : - instanciate a class with an unknown number of parameters in the constructor - call an object's method, also with an unknown number of parameters ? ...
2
by: Tommie Nygren | last post by:
For different reasons I am reading an array of bytes from a file in my ..jar-file and from this I want to create a PNG image using Image.createImage(myArray, 0 , myArray.length). I had a...
3
by: Mike D | last post by:
I have an array like array = "1,2,3|,2,4,6| ...) There will be an unknown number a values between the | and an uknown total number of values. I need to get the average of the number between...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
15
by: fdunne2 | last post by:
The following C-code implements a simple FIR filter: //realtime filter demo #include <stdio.h> #include <stdlib.h> //function defination float rtFilter1(float *num, float *den, float...
17
by: gk245 | last post by:
For instance, if i had a array like this: array = {1, 2, 3, 5, 6, ......}; How do i tell C go get me the number of values in the array? Not the value itself, but how MANY of them there are. ...
38
by: djhulme | last post by:
Hi, I'm using GCC. Please could you tell me, what is the maximum number of array elements that I can create in C, i.e. char* anArray = (char*) calloc( ??MAX?? , sizeof(char) ) ; I've...
4
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i want to retrieve the values which are arrayed on...
33
by: Adam Chapman | last post by:
Hi, Im trying to migrate from programming in Matlab over to C. Im trying to make a simple function to multiply one matrix by the other. I've realised that C can't determine the size of a 2d...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.