Solved

# Array & Assignement - Question

Posted on 2006-05-24
Medium Priority
160 Views
Last Modified: 2010-04-23
Dim A(20), B(20), C(), D As Integer
For D = 0 To 19
A(D) = 3
B(D) = 4
Next
MsgBox(A(1) & vbTab & B(1))  'Outputs 3     4
C = A
A = B
B = C
MsgBox(A(1) & vbTab & B(1))  'Outputs 4    3

What exactly is happening during the C = A, A = B, B = C stage?

Are A, B, and C references to separate array objects that contain integers (originally)?

So, C = A makes C and A both point at the Array Object containing 20 3's, correct?

A = B changes the integer-array-reference, A, to point to the array containing 20 3's, correct?

Thanks, this is a little fuzzy to me in VB (whereas it is very eplicit how such things work in C++)
0
Question by:oxygen_728
• 2
4 Comments

LVL 14

Accepted Solution

ptakja earned 1000 total points
ID: 16757348
I think you got it.

After your loop runs...
A() = 3's
B() = 4's

C = A --> C = 3's --> C points to the array A (with the 3's in it).
A = B --> A = 4's --> A now points to the array B (with the 4's in it)
B = C --> B = 3's --> B now points to C (and at this point C is pointing to A, so C has 3's in it.)

Does that make any sense?
0

Author Comment

ID: 16757766
Ya, I am more concerned with what exactly what is happening with the references on a very low level
0

LVL 34

Assisted Solution

Sancler earned 1000 total points
ID: 16759369
I'm not sure whether this is, or illustrates, what you mean by "on a very low level".  But try this code

Dim A(10), B(20), C(), D As Integer
For D = 0 To 9
A(D) = 3
Next
For D = 0 To 19
B(D) = 4
Next
MsgBox(A.Length & vbTab & B.Length) ' & vbTab & C.Length)
C = A
MsgBox(A.Length & vbTab & B.Length & vbTab & C.Length)
A = B
MsgBox(A.Length & vbTab & B.Length & vbTab & C.Length)
B = C
MsgBox(A.Length & vbTab & B.Length & vbTab & C.Length)
C(1) = 9
MsgBox(A(1) & vbTab & B(1) & vbTab & C(1))

This illustrates, I think, that the "=" operator as between arrays of the same type makes that on the left REFER TO that on the right.  Up until the last two lines it might appear that it made that on the left into another object identical to that on the right.  But the fact that it is only the references that is made the same, rather than the objects themselves, is illustrated by the fact that changing a value in C also changes it in B.

Roger
0

Author Comment

ID: 16783011
thanks
0

## Featured Post

Question has a verified solution.

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

XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
###### Suggested Courses
Course of the Month13 days, 16 hours left to enroll

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

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