Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hard times with arrays

0 views
Skip to first unread message

Rachel

unread,
Nov 25, 2002, 8:49:44 PM11/25/02
to
Ok, I think there should be a simple, one line solution to this with a "you
fool" prefix...

Have a simple webpage that will take certain details from the visitor. The
form is controlled, so there won't be more than 6 fields, but of course, I
can't predict how many entries. I'd like to put these details into an array
(as it works nicely with the rest of the affected pages / site), but I've
gone over this many times now and I can't find a way to just go string
details[][6];. It always wants there to be a value in the first dimension
:(

What I've done in the declaration is : string[,] kartArray = new
string[3,6]; just to check that the page is working fine, but I want to
remove the '3' so that it's not limited to 3, but rather unlimited. Please
tell me this is possible. I've tried variations to this, but no matter
what, I need to specify the numbers. Any ideas on what I could do?

Thanks in advance :)


Chad Myers

unread,
Nov 25, 2002, 10:52:51 PM11/25/02
to

"Rachel" <nos...@nodomain.universe> wrote in message
news:aruk2j$rlu$1...@towncrier.cc.monash.edu.au...

> Ok, I think there should be a simple, one line solution to this with a
"you
> fool" prefix...
>
> Have a simple webpage that will take certain details from the visitor.
The
> form is controlled, so there won't be more than 6 fields, but of
course, I
> can't predict how many entries. I'd like to put these details into an
array
> (as it works nicely with the rest of the affected pages / site), but
I've
> gone over this many times now and I can't find a way to just go string
> details[][6];. It always wants there to be a value in the first
dimension
> :(

First, if you have a dynamic number of entries, you'll be much happier
with an ArrayList or Hashtable.

To answer your question, you have a two-dimension array, so in order
to access one of the 2nd dimensions, you must first tell it which
1st dimension you want.

If you had a table with unlimited rows and 2 columns, and you wanted
to reference column 2, which row should it grab column 2 from?

You should create a simple object with 6 properties representing
the 6 fields.

Then you should have an ArrayList. You create a new VisitorDetails
object (or whatever you call it), set the 6 properties from the
form fields, add them to the ArrayList and pass the ArrayList around.

> What I've done in the declaration is : string[,] kartArray = new
> string[3,6]; just to check that the page is working fine, but I want
to
> remove the '3' so that it's not limited to 3, but rather unlimited.
Please
> tell me this is possible. I've tried variations to this, but no
matter
> what, I need to specify the numbers. Any ideas on what I could do?

Arrays are fixed. Always. You can create a new array that's slightly
larger and then copy the elements from the original array to achieve
a "resize" of the array, but you can never actually change the original
array.

You should use ArrayList. It functions much like an unbounded Array.

-c


Rachel

unread,
Nov 26, 2002, 1:17:15 AM11/26/02
to
Wow :D Good idea, just had a quick further look at ArrayList as an option,
and sounds fitting. Thanks :)

"Chad Myers" <cmy...@N0.SP.4M.austin.rr.com> wrote in message
news:neCE9.63984$8D.15...@twister.austin.rr.com...

0 new messages