PC Review


Reply
Thread Tools Rate Thread

Dynamic Creation of Arrays - Sorting into Bins problem

 
 
Chris Flockhart
Guest
Posts: n/a
 
      11th Aug 2011
Hi

In my vba code, I have an array of "structures", where the structure
has several fields including a User Name and other parameters. The
list is effectively unsorted as it has been created by reading a file
that contains entries in chronological order.

So far so good.

What I now want to do is to go through this array and produce a set of
new arrays, one per individual User Name, which each contain entries
from the original array that are specific to that UserName.

I also want to maintain a further array which keeps track of all of
the User specific arrays I have created.

This is a classic issue of processing a list into bins, dynamically
creating and reallocating the result bins as each item in the original
list is processed. I would have no problem implementing this in C,C++,
or Java, but I am unsure as to how to create an array from thin air at
run time in VBA.

I do not want to use magic numbers to create a "large enough" array,
as I would like this solution to be scalable.

Can anyone either describe how to create arrays completely dynamically
in vba, or point me at code which handles the sorting into bins
problem.

Thanks

Chris
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      11th Aug 2011
A very good place to start are these 3 subject areas in Excel VBA help...
Using Arrays
Declaring Arrays
Understanding Parameter Arrays
'---
Sub Demo()
Dim aThinAir() As String
Dim x As Long
Dim y As Long
Dim z As Long

x = 10: y = 5: z = 5
ReDim aThinAir(1 To x, 1 To y, 1 To z)
aThinAir(1, 2, 3) = "sludge"

MsgBox aThinAir(1, 2, 3)
End Sub
'---
Jim Cone
Portland, Oregon USA .
http://www.mediafire.com/PrimitiveSoftware .
(free and commercial excel programs)





"Chris Flockhart" <(E-Mail Removed)>
wrote in message
news:84919946-78c9-4792-b1d5-(E-Mail Removed)...
> Hi
>
> In my vba code, I have an array of "structures", where the structure
> has several fields including a User Name and other parameters. The
> list is effectively unsorted as it has been created by reading a file
> that contains entries in chronological order.
>
> So far so good.
>
> What I now want to do is to go through this array and produce a set of
> new arrays, one per individual User Name, which each contain entries
> from the original array that are specific to that UserName.
>
> I also want to maintain a further array which keeps track of all of
> the User specific arrays I have created.
>
> This is a classic issue of processing a list into bins, dynamically
> creating and reallocating the result bins as each item in the original
> list is processed. I would have no problem implementing this in C,C++,
> or Java, but I am unsure as to how to create an array from thin air at
> run time in VBA.
>
> I do not want to use magic numbers to create a "large enough" array,
> as I would like this solution to be scalable.
>
> Can anyone either describe how to create arrays completely dynamically
> in vba, or point me at code which handles the sorting into bins
> problem.
>
> Thanks
>
> Chris



 
Reply With Quote
 
GS
Guest
Posts: n/a
 
      11th Aug 2011
on 8/11/2011, Chris Flockhart supposed :
> Hi
>
> In my vba code, I have an array of "structures", where the structure
> has several fields including a User Name and other parameters. The
> list is effectively unsorted as it has been created by reading a file
> that contains entries in chronological order.
>
> So far so good.
>
> What I now want to do is to go through this array and produce a set of
> new arrays, one per individual User Name, which each contain entries
> from the original array that are specific to that UserName.
>
> I also want to maintain a further array which keeps track of all of
> the User specific arrays I have created.
>
> This is a classic issue of processing a list into bins, dynamically
> creating and reallocating the result bins as each item in the original
> list is processed. I would have no problem implementing this in C,C++,
> or Java, but I am unsure as to how to create an array from thin air at
> run time in VBA.
>
> I do not want to use magic numbers to create a "large enough" array,
> as I would like this solution to be scalable.
>
> Can anyone either describe how to create arrays completely dynamically
> in vba, or point me at code which handles the sorting into bins
> problem.
>
> Thanks
>
> Chris


Jim's suggestion is indeed a good place to start!

Typically, I dump the file contents into a Variant (causing a dynamic
array) using the Split() function and specifying vbCrLf as the
delimiter. My files include headings (field names) in the first line,
but this is not necessary if, as you say, the data is structured.

Each line of the file contains a 'record' where each field of data is
delimited by a comma (or some other character). Looping the dynamic
array lets me Split() each element into a temp array to process it
however I need.

Perhaps this approach might work for you.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


 
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
Commandbars dynamic menu creation problem =?Utf-8?B?R3VzRXZhbnM=?= Microsoft Excel Programming 6 6th Apr 2006 07:21 PM
GridView Dynamic creation problem Larry F. Burge Microsoft ADO .NET 0 30th Nov 2005 03:23 PM
Dynamic creation of object problem Harry F. Harrison Microsoft ASP .NET 1 11th Aug 2004 01:49 AM
dynamic sorting with arrays =?Utf-8?B?SmFtZXM=?= Microsoft Excel Worksheet Functions 0 27th Jan 2004 03:56 PM
Problem with generics and dynamic class creation andrew queisser Microsoft C# .NET 1 21st Nov 2003 11:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:16 PM.