# assignment statements for arrays

I would like to fill a two dimensional variable array:
dim array2D(9,9) as integer
dim x, y, a, b as integer
for x = 1 to 10
for y = 1 to 10
a = 25
b = 35
array2D(x, y) = what do I put here to fill the array
elements with 25 and 35 each time it
goes through the loop?

###### Who is Participating?

Commented:
First off.
Dont do this..  Dim X,Y,A,B as integer..
unless you want X,Y,and A to be Variants, and B to be an integer.

This isnt C
Do This
Dim X as Integer, Y as integer, A as integer, B as Integer

Second..
Dim Array1D(9) is not the same as in C
The above array in VB gets you
either an array from 0 to 9 or and array from 1 to 9
depending on your Option Base <default is 0>
To be Safe, in this example..
Do this
Dim Array2d(1 to 10,1 to 10)
<since that is what you use later>

Number Three...
You aren't making sense as to what you want to do
Array2D(1,1) is an integer and can only hold one item.. either
25 or 35.. <i guess that is what you want to do>
I guess you can do this.,,
Array2D(x,y) = a + b

but that shoves 60 into each element of the array.
0

Commented:
Timothy,
I have a very basic question about what you are trying to do.  You have defined a 2 dimensional array of integers.  You say you want to fill the array with 25 and 35.  Each element of the array will only hold one number (unless you want to AND them before you store them in the array, which I doubt).

If you explain a little more what you want to do with those 2 numbers, I will be able to fix your code.
0

Author Commented:
a single dimension array(1 to 10) will have ten elements:
array(1) through array(10). Correct?

a two dimensional array2(1 to 10, 1 to 10) will have ten elements:

array(1, 1) through array(10, 10). For a total of 100 individual elements. I want to no the right side of the assignment statement to fill each of the 100 individual elements with a seperate value so that array(1, 1) will contain the values of
25 and 35 respectfully and array(2, 2) will have 25, 35 respectfully.
0

Commented:
No.. One Dimensional array is like a piece of notepaper..
Assuming that you can write only one think per line..

A Two Dimensionnal array is like a Calandar page..
where you can have multiple Columns <days of the Week>   and Multiple Rows. <1st week of month> <2nd week of month> etc..
but Each BOX in the Calendar can only be for ONE day..  <One item..ie  One integer>
0

Author Commented:
I must be confused regarding arrays. A 1D array(1 to 10) has
ten values array(1), array(2), etc.

A 2d array has two values for each element or two elements of each value (I may be switching the terms). What ever is the proper terminology, I what an array that would look like this if it could be printed:

25  10
65  34
23  65
56  76
Etc.
0

Commented:
If you need to put 2 numbers in each position of a 2 dimensional array, you would actually need a 3 dimensional array.

Dim Array3d(1 to 10, 1 to 10, 1 to 2)

Then Array3d (1,1,1) = 25; position Array3d(1,1,2)=35
Similarily Array3d(6,4,1)=25; position Array3d(6,4,2)=35

Is this something like you want to do?
0

Commented:
If you need to put 2 numbers in each position of a 2 dimensional array, you would actually need a 3 dimensional array.

Dim Array3d(1 to 10, 1 to 10, 1 to 2)

Then Array3d (1,1,1) = 25; position Array3d(1,1,2)=35
Similarily Array3d(6,4,1)=25; position Array3d(6,4,2)=35

Is this something like you want to do?
0

Commented:
OK.. you Want a two Dimensionsal Array.
like this
25 lines.. Two items

Dim Array2D(1 to 25 , 1 to 2) as integer
dim x as integer, a as integer, b as integer
a = 25
b = 35
for x = 1 to 10
array2D(x, 1) = a
array2D(x, 2) = b
next x
0

Author Commented:
The Answerman's comment is what I what. I have to have two assignment statements.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.