PC Review


Reply
Thread Tools Rate Thread

Append to an array

 
 
maweilian
Guest
Posts: n/a
 
      24th Jun 2009

This is my best guess on how to do this:

Dim testvalue, testarray()
For testvalue = 50 To 100 Step 5
ReDim Preserve testarray(UBound(testarray) + 1)
testarray(UBound(testarray)) = testvalue
Next testvalue

So the goal is to start with an array of unknown size and simply add values
until complete.

I am sure this is very flawed. Would appreciate any help.

Will

 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      24th Jun 2009

What is wrong with your code. It is not flawed.

I found the code below to be useful. You code created an extra item in the
array. When you do redim testarray(1) it really creates two items in the
array. A zero index and a one index. My code makes the aray exactly the
same size as the data that is inside. it really doesn't make a difference
except when you create a UDF function. then it sometimes matters. for
example you returned an array to the worksheet function Average. The average
would not be correct because you would be dviding by one more item then you
really had.

Sub test()

Dim testvalue, testarray

For testvalue = 50 To 100 Step 5
If IsArray(testarray) Then
ReDim Preserve testarray(0 To (UBound(testarray) + 1))
Else
ReDim testarray(0 To 0)
End If
testarray(UBound(testarray)) = testvalue
Next testvalue

End Sub

"maweilian" wrote:

> This is my best guess on how to do this:
>
> Dim testvalue, testarray()
> For testvalue = 50 To 100 Step 5
> ReDim Preserve testarray(UBound(testarray) + 1)
> testarray(UBound(testarray)) = testvalue
> Next testvalue
>
> So the goal is to start with an array of unknown size and simply add values
> until complete.
>
> I am sure this is very flawed. Would appreciate any help.
>
> Will
>

 
Reply With Quote
 
Bernd P
Guest
Posts: n/a
 
      24th Jun 2009
Hello Will,

Nothing wring with your code, I think.

Its just the question how much effort you want to invest into your
approach.

An example I developed you can see here:
http://www.sulprobil.com/html/pstat.html

Regards,
Bernd
 
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
Append an array list to another one Curious Microsoft Dot NET 2 31st Mar 2009 03:39 PM
Append array to recordset Tom Microsoft Access VBA Modules 1 22nd Jan 2009 12:47 PM
Append One Array to Another, and Consolidate =?Utf-8?B?U3RyYXR1c2Vy?= Microsoft Excel Programming 47 25th Nov 2006 07:26 AM
Trying to append to file using an array Susan Hayes Microsoft Excel Programming 1 5th Jan 2006 08:55 AM
Append data from a column to separate table array miss_q Microsoft Excel Programming 5 12th Dec 2005 11:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:51 PM.