Solved

assignment statements for arrays

Posted on 1998-10-03
9
195 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
  • 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 50 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now