-
Sep 18th, 2014, 10:32 AM
#1
[RESOLVED] Array to Array
Dim Array1(0 To 10) As Integer
Dim Array2(0 To 10) As Integer
Array2 = Array1
Why can I not do this?
I get Can't assign to array error
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Sep 18th, 2014, 10:54 AM
#2
Re: Array to Array
Just the way it is with static arrays. I imagine that the SafeArray structure that describes those arrays internally, includes the flag: FADF_FIXEDSIZE. That flag says that the array may not be resized or reallocated.
No errors:
Code:
Dim Array1() As Integer
Dim Array2() As Integer
ReDim Array1(0 To 10)
ReDim Array2(0 To 10)
Array2 = Array1
Updated: Yep, just verified it. The SafeArray structure returned from such an array includes the flag to prevent resizing/reallocation.
Last edited by LaVolpe; Sep 18th, 2014 at 11:15 AM.
-
Sep 18th, 2014, 11:37 AM
#3
Re: Array to Array
If you make array2 dynamic you should be okay
Code:
Dim Array1(0 To 10) As Integer
Dim Array2() As Integer
Dim i As Integer
For i = 0 To 10
Array1(i) = (i + 1) ^ 2
Next i
Array2 = Array1
For i = 0 To UBound(Array2)
Debug.Print Array2(i)
Next i
-
Sep 18th, 2014, 11:46 AM
#4
Re: Array to Array
Thanks MT for the info however I have to use LaVolpe's way because later I am going to reverse the assignment
Array1 = Array2
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Sep 18th, 2014, 01:46 PM
#5
Re: Array to Array
Thanks, LaVolpe, that's what I need.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Sep 18th, 2014, 01:59 PM
#6
Re: Array to Array
Originally Posted by jmsrickland
Thanks, LaVolpe, that's what I need.
You're welcome.
Note that if both arrays will start with same values, just populate one & set the unpopulated one equal the populated one. Can save a line of code or more at times.
-
Sep 20th, 2014, 11:51 AM
#7
Re: [RESOLVED] Array to Array
As with so many of these fundamental issues, this is covered in the VB6 documentation.
See Advanced Features of Arrays.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|