Solved

# assignment statements for arrays

Posted on 1998-10-03
214 Views
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?

0
Question by:timothy1
• 3
• 3
• 3

LVL 3

Expert Comment

ID: 1437963
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

LVL 3

Accepted Solution

ID: 1437964
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

Author Comment

ID: 1437965
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

LVL 3

Expert Comment

ID: 1437966
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 Comment

ID: 1437967
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

LVL 3

Expert Comment

ID: 1437968
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

LVL 3

Expert Comment

ID: 1437969
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

LVL 3

Expert Comment

ID: 1437970
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 Comment

ID: 1437971
The Answerman's comment is what I what. I have to have two assignment statements.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…