Solved

Keep array values when ReDimed

Posted on 2004-03-24
9
615 Views
Last Modified: 2010-05-18
Lets say I have an array A(624, 9). it is already populated with values. How can i ReDim it to A(78, 78) and keep the original values (exactly the first 6241 values in A(624, 9), in the same order they appear when running from top to bottom, reading line by line in left to right order. This way, they are to form a square ReDimed array - A(78, 78) exactly filled with 6241 values taken orderly from the original A).
E. G.
original A = a b c d
                  e f g h
                  i  j k  l
                 m n o p
                 q  r s  t
                 u  v w x

ReDimed A = a b c d e f
                    g h i  j  k l
                   m n o p q r
                   s  t  u v w x

many thanks.
0
Comment
Question by:liorim2
[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
  • 2
  • 2
  • +2
9 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10665966
Just add preserve after redim

Redim Preserve YourArray(Size)


-Brian
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10665981

'Keeps values in A and adds 1 to size of the array

Redim Preserve A(Ubound(A) + 1)
A(Ubound(A)) = "NEWLY ADDED A!"
0
 
LVL 8

Expert Comment

by:william_jwd
ID: 10666031
I am not sure that the preserve will work in this situation.

You can declare another array with B(6241).  Populate all the values from A(624, 9) to B(6241) and then after the ReDim A(78, 78), you can copy B(6241) to A(78, 78).
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:liorim2
ID: 10666345
William, you right. how do i copy B(6241) to A(78, 78)??
0
 
LVL 8

Accepted Solution

by:
william_jwd earned 500 total points
ID: 10666406
try this,


ctr = 0
for i = 1 to 624 loop
  for j = 1 to 9 loop
    ctr = ctr + 1
    b(ctr) = a(i, j)
  next
next

redim a(78, 78)

ctr = 0
for i = 1 to 78 loop
  for j = 1 to 78 loop
    ctr = ctr + 1
    a(i, j) = b(ctr)
  next
next
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10667068
by the way 78 by 78 is smaller than 624 by 9, and neither is 6241

78 * 78 = 6084

624 * 9 = 5616

so how do you expect to keep the 'first 6241' values, when you don't have 6241 values in the first place?

AW


0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10667136
Hi AW / all,

An array of A(624, 9) holds 625*10 values being zero-relative (i.e. 0..624, 0..9 is 625 * 10).

PS. Further discussion regarding quick manipulation of array values using API calls:

http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_20902787.html

Namely, the "RTLCopyMemory" function.

BFN,

fp.
0
 

Author Comment

by:liorim2
ID: 10667241
Arthur Wood, did you get fanpages's answer?
William, i dont know whats wrong with me today... IT IS THAT SIMPLE!! Anyway, you the man...

Million thanks.
Lior.
0
 
LVL 8

Expert Comment

by:william_jwd
ID: 10667968
You're welcome Lior...

William.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

734 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