?
Solved

assignment statements for arrays

Posted on 1998-10-03
9
Medium Priority
?
243 Views
Last Modified: 2010-04-30
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
Comment
Question by:timothy1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 3

Expert Comment

by:GeneM
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

by:
TheAnswerMan earned 200 total points
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

by:timothy1
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:TheAnswerMan
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

by:timothy1
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

by:GeneM
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

by:GeneM
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

by:TheAnswerMan
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

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question