PC Review


Reply
Thread Tools Rate Thread

Assign different sized arrays

 
 
Wes
Guest
Posts: n/a
 
      11th Aug 2008
Forgive the semi psuedo code.

Dim arr1(10), arr2(5)
arr1 is clear, arr2 is populated

Will this statement work?
arr1=arr2

If so, do arr1(6) to arr1(10) contain nulls?

Thxs
 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      11th Aug 2008
Hi,
no, you can not do such assignment directly.

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com

"Wes" <(E-Mail Removed)> wrote in message
news:B3229D7A-F202-480F-94E3-(E-Mail Removed)...
> Forgive the semi psuedo code.
>
> Dim arr1(10), arr2(5)
> arr1 is clear, arr2 is populated
>
> Will this statement work?
> arr1=arr2
>
> If so, do arr1(6) to arr1(10) contain nulls?
>
> Thxs


 
Reply With Quote
 
Michel Walsh
Guest
Posts: n/a
 
      11th Aug 2008
Na. Use dimension-less array and use only one variable per dim.


Dim arr1(10) AS long
Dim arr2() AS long

...
arr2=arr1


and the arr2 variable will get a COPY of arr"1:

arr1(5)=5
arr2=arr1
arr1(5)=55
Debug.Print arr1(5) = arr2(5)


if the arr2 was just as reference, not a copy, the last statement would be
true.



Vanderghast, Access MVP


"Wes" <(E-Mail Removed)> wrote in message
news:B3229D7A-F202-480F-94E3-(E-Mail Removed)...
> Forgive the semi psuedo code.
>
> Dim arr1(10), arr2(5)
> arr1 is clear, arr2 is populated
>
> Will this statement work?
> arr1=arr2
>
> If so, do arr1(6) to arr1(10) contain nulls?
>
> Thxs



 
Reply With Quote
 
Graham Mandeno
Guest
Posts: n/a
 
      11th Aug 2008
Hi Wes

If you have already declared Arr1 as an array, then no, you cannot do this.
You will get a compile error: Can't assign to an array.

If you declared Arr1 as Variant and then used ReDim to make it an array,
then yes, you can assign Arr2 to it, but it will inherit the dimensions and
data type of Arr2.

So, if you declared Arr2(5) as Long, then Arr1 would become an array(5) of
Long.

You could then ReDim Preserve Arr1(10) but elements 6-10 would be 0, not
Null.

If Arr2 were declared as an array of Variant, then elements 6-10 would be
Empty, not Null.

The usual way to copy elements between incongruent arrays is to use a For
loop.
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

"Wes" <(E-Mail Removed)> wrote in message
news:B3229D7A-F202-480F-94E3-(E-Mail Removed)...
> Forgive the semi psuedo code.
>
> Dim arr1(10), arr2(5)
> arr1 is clear, arr2 is populated
>
> Will this statement work?
> arr1=arr2
>
> If so, do arr1(6) to arr1(10) contain nulls?
>
> Thxs



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jagged Arrays Problem - How to Assign Arrays to an Array Zigs Microsoft Excel Programming 3 11th Apr 2007 01:39 AM
dynamically sized arrays Carlos Microsoft C# .NET 5 26th Aug 2005 02:01 PM
How to use linest with variably sized data arrays? tahsin.alam@db.com Microsoft Excel Worksheet Functions 0 13th Apr 2005 04:56 PM
Comparing Different Sized Arrays ExcelMonkey Microsoft Excel Programming 3 20th Feb 2005 04:49 AM
Printing a legal sized document on letter sized paper Paula O. Microsoft Excel Programming 0 2nd Feb 2004 06:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:46 PM.