VBA Excel: How to put classes into an array - excel

Is there anyway that I can put various classes into an array so that instead of hard-coding like:
set var1 = new cls1
set var2 = new cls2
we can do:
varArr = array ( var1, var2...)
clsArr = array (cls1, cls2...)
and now I just loop thru varArr and clsArr to set new class accordingly, like:
sub setNew(x as double)
set varArr(x) = new clsArr(x)
end sub
I did try but it didn't work, please help me out
Thank you very much !
Triet (mr)

I try, but my knowledge also limited.
First of all I do not think you can put class into an array. You can put objects. I also failed to use the array() function.
Please see how I proceeded with some demonstration:
This is the class module, containing a value, the property and a primitive print sub:
Private nr As Integer 'Use as identification
Sub cPrint()
MsgBox "Object ID: " & nr
End Sub
Property Let ID(v As Integer)
nr = v
End Property
In the module in the first cycle I create the object, put the ID value. In the second one all ID values are printed. I hope you can use it for your purposes.
Sub clsTest()
Dim varArr(1 To 5) As cls1
Dim i As Integer
For i = 1 To 5
Set varArr(i) = New cls1
varArr(i).ID = i
Next
For i = 1 To 5
varArr(i).cPrint
Next
End Sub

Related

Why can't I declare my Class Object as such?

I am currently creating a Class Object for a VBA file, its objective is to act as a range dictionary that can be passed single cells. If this cell is contained in one of the ranges, it returns the value associated to the corresponding range key. The class name is "rangeDic".
It is in the making so its functionalities are not implemented yet. Here's the code:
Private zone() As String
Private bounds() As String
Private link As Dictionary
Const ContextId = 33
'Init zone
Private Sub Class_Initialize()
Set link = New Dictionary
ReDim zone(0)
ReDim bounds(0)
End Sub
'properties
Property Get linkDico() As Dictionary
Set linkDico = link
End Property
Property Set linkDico(d As Dictionary)
Set link = d
End Property
Property Get pZone() As String()
pZone = zone
End Property
Property Let pZone(a() As String)
Let zone = a
End Property
'methods
Public Sub findBounds()
Dim elmt As String
Dim i As Integer
Dim temp() As String
i = 1
For Each elmt In zone
ReDim Preserve bounds(i)
temp = Split(elmt, ":")
bounds(i - 1) = temp(0)
bounds(i) = temp(1)
i = i + 2
Next elmt
End Sub
I was trying to instanciate it in a test sub in order to debug mid conception. Here's the code:
Sub test()
Dim rd As rangeDic
Dim ran() As String
Dim tabs() As Variant
Dim i As Integer
i = 1
With ThisWorkbook.Worksheets("DataRanges")
While .Cells(i, 1).Value <> none
ReDim Preserve ran(i - 1)
ReDim Preserve tabs(i - 1)
ran(i - 1) = .Cells(i, 1).Value
tabs(i - 1) = .Cells(i, 3).Value
i = i + 1
Wend
End With
Set rd = createRangeDic(ran, tabs)
End Sub
Public Function createRangeDic(zones() As String, vals() As Variant) As rangeDic
Dim obje As Object
Dim zonesL As Integer
Dim valsL As Integer
Dim i As Integer
zonesL = UBound(zones) - LBound(zones)
valsL = UBound(vals) - LBound(vals)
If zonesL <> valsL Then
Err.Raise vbObjectError + 5, "", "The key and value arrays are not the same length.", "", ContextId
End If
Set obje = New rangeDic
obje.pZone = zones()
For i = 0 To 5
obje.linkDico.add zones(i), vals(i)
Next i
Set createRangeDic = obje
End Function
Take a look at line 2 of Public Function createRangeDic. I have to declare my object as "Object", if I try declaring it as "rangeDic", Excel crashes at line obje.pZone = zones(). Upon looking in the Windows Event Log, I can see a "Error 1000" type of application unknown error resulting in the crash, with "VB7.DLL" being the faulty package.
Why so ? Am I doing something wrong ?
Thanks for your help
Edit: I work under Excel 2016
It looks like this is a bug. My Excel does not crash but I get an "Internal Error".
Let's clarify a few things first, since you're coming from a Java background.
Arrays can only be passed by reference
In VBA an array can only be passed by reference to another method (unless you wrap it in a Variant). So, this declaration:
Property Let pZone(a() As String) 'Implicit declaration
is the equivalent of this:
Property Let pZone(ByRef a() As String) 'Explicit declaration
and of course, this:
Public Function createRangeDic(zones() As String, vals() As Variant) As rangeDic
is the equivalent of this:
Public Function createRangeDic(ByRef zones() As String, ByRef vals() As Variant) As rangeDic
If you try to declare a method parameter like this: ByVal a() As String you will simply get a compile error.
Arrays are copied when assigned
Assuming two arrays called a and b, when doing something like a = b a copy of the b array is assigned to a. Let's test this. In a standard module drop this code:
Option Explicit
Sub ArrCopy()
Dim a() As String
Dim b() As String
ReDim b(0 To 0)
b(0) = 1
a = b
a(0) = 2
Debug.Print "a(0) = " & a(0)
Debug.Print "b(0) = " & b(0)
End Sub
After running ArrCopy my immediate window looks like this:
As shown, the contents of array b are not affected when changing array a.
A property Let always receives it's parameters ByVal regardless of whether you specify ByRef
Let's test this. Create a class called Class1 and add this code:
Option Explicit
Public Property Let SArray(ByRef arr() As String)
arr(0) = 1
End Property
Public Function SArray2(ByRef arr() As String)
arr(0) = 2
End Function
Now create a standard module and add this code:
Option Explicit
Sub Test()
Dim c As New Class1
Dim arr() As String: ReDim arr(0 To 0)
arr(0) = 0
Debug.Print arr(0) & " - value before passing to Let Property"
c.SArray = arr
Debug.Print arr(0) & " - value after passing to Let Property"
arr(0) = 1
Debug.Print arr(0) & " - value before passing to Function"
c.SArray2 arr
Debug.Print arr(0) & " - value after passing to Function"
End Sub
After running Test, my immediate window looks like this:
So, this simple test proves that the Property Let does a copy of the array even though arrays can only be passed ByRef.
The bug
Your original ran variable (Sub test) is passed ByRef to createRangeDic under a new name zones which is then passed ByRef again to pZone (the Let property). Under normal circumstances there should be no issue with passing an array ByRef as many times as you want but here it seems it is an issue because the Property Let is trying to make a copy.
Interestingly if we replace this (inside createRangeDic):
obje.pZone = zones()
with this:
Dim x() As String
x = zones
obje.pZone = x
the code runs with no issue even if obje is declared As rangeDic. This works because the x array is a copy of the zones array.
It looks that the Property Let cannot make a copy of an array that has been passed ByRef multiple times but it works perfectly fine if it was passed ByRef just once. Maybe because of the way stack frames are added in the call stack, there is a memory access issue but difficult to say. Regardless what the problem is, this seems to be a bug.
Unrelated to the question but I must add a few things:
Using ReDim Preserve in a loop is a bad idea because each time a new memory is allocated for a new (larger) array and each element is copied from the old array to the new array. This is very slow. Instead use a Collection as
#DanielDuĊĦek suggested in the comments or minimize the number of ReDim Preserve calls (for example if you know how many values you will have then just dimension the array once at the beginning).
Reading a Range cell by cell is super slow. Read the whole Range into an array by using the Range.Value or Range.Value2 property (I prefer the latter). Both methods returns an array as long as the range has more than 1 cell.
Never expose a private member object of a class if that object is responsible for the internal workings of the class. For example you should never expose the private collection inside a custom collection class because it breaks encapsulation. In your case the linkDico exposes the internal dictionary which can the be modified from outside the main class instance. Maybe it does not break anything in your particular example but just worth mentioning. On the other hand Property Get pZone() As String() is safe as this returns a copy of the internal array.
Add Option Explicit to the top of all your modules/classes to make sure you enforce proper variable declaration. Your code failed to compile for me because none does not exist in VBA unless you have it somewhere else in your project. There were a few other issues that I found once I turned the option on.

VBA - create unique ID of String / Hash

First of all I want so say sorry for not showing any code but right now I need some guidelines on how to take out a unique ID of a string.
So I have some problems of how to organize data. Lets say that the data is organized so that each dataID has their unique name. I collect the data into a array that holds it.
The problem I now have is that I want a easy way to search for these nameID. Imagine that the data is a lot bigger and contain more than a few hundred of different unique combinations of nameID's. Therefor I do not think searching for the id itself would be appropriate and I'm thinking of creating an hash that I could use an algorithm on to search the array. I want to do this because later on I will compare the names and add the values to the respective nameID. Keep in mind that the nameID will most of the time have the same structure but eventually a new name like total_air could be implemented and then I need to search in the array to get right value.
Updated:
Example of an code that collect the data from excel:
For Each targetSheet In wb.Worksheets
With targetSheet
'Populate the array
xData(0) = Application.Transpose(Range(Cells(1, 1), Cells(1, 1).End(xlDown)).Value2)
cnt = UBound(xData(0))
End With
Call dData.init(cnt)
'Populate the objectarray
dData.setNameArray = xData(0)
Next targetSheet
Type object:
Private index As Integer
Private id As String
Private nameID() As Variant
Private data() As Variant
Private cnt As Integer
Public Sub init(value As Integer)
index = 0
cnt = value
id = ""
ReDim nameID(0 To cnt)
ReDim data(0 To cnt)
End Sub
Property Let setID(value As String)
id = value
End Property
Property Let setNameArray(value As Variant)
nameID = value
End Property
dList that inherit the dataStruct:
Private xArray() As dataStruct
Private listInd As Integer
Public Sub init(cnt As Integer)
ReDim xArray(1 To cnt)
Dim num As Integer
For num = 1 To cnt
Set xArray(num) = New dataStruct
Next
listInd = 1
End Sub
Property Let addArray(value As dataStruct)
Set xArray(listInd) = value
listInd = listInd + 1
End Property
How the hole list will look like:
I would strongly advocate using a dictionary. Not only is it much faster to find an item (I would assume that it is implemented with some kind of hashing), it has big advantages when it comes to adding or removing items.
When you have an array and want to add an item, you either have always to use redim preserve which is really expensive, or you define the array larger than initially needed and always have to keep the information how many items are really used. And deleting an item from an array is rather complicated.
You cannot add a typed variable as item value into a dictionary, but you can add a object. So instead of your Type definition, create a simple class module, containing only these lines (of course you can create the class with properties, getter and setter but that's irrelevant for this example)
Public id As Long
Public name As String
Public value As Long
Then, dealing with the dictionary is rather simple (note that you have to add a reference to the Microsoft Scripting Runtime
Option Explicit
Dim myList As New Dictionary
Sub AddItemValues(id As Long, name As String, value As Long)
Dim item As New clsMyData
With item
.id = id
.name = name
.value = value
End With
Call AddItem(item)
End Sub
Sub AddItem(item As clsMyData)
If myList.Exists(item.id) Then
set myList(item.id) = item
Else
Call myList.Add(item.id, item)
End If
End Sub
Function SearchItem(id As Long) As clsMyData
If myList.Exists(id) Then
Set SearchItem = myList(id)
Else
Set SearchItem = Nothing
End If
End Function
Function SearchName(name As String) As clsMyData
Dim item As Variant
For Each item In myList.Items
If item.name = name Then
Set SearchName = item
Exit Function
End If
Next item
Set SearchName = Nothing
End Function
So as long as you deal with Id's, the dictionary will do all the work for you. Only if you search for the name, you have to loop over all items of the dictionary, which is as easy as looping over an array.
Some test (of course you should add some error handling)
Sub test()
Call AddItemValues(32, "input_air", 0)
Call AddItemValues(45, "air_Procent", 99)
Call AddItemValues(89, "output_air", 34)
Debug.Print SearchItem(45).name
Debug.Print SearchName("output_air").value
' Change value of output_air
Call AddItemValues(89, "output_air", 1234)
Debug.Print SearchName("output_air").value
End Sub

How to speed up the comparision of 2 collections in VBA?

I have written a macro that gets a collection of collection and than takes two of the collections and gives me the similarity.
Now if I compare the two collections with a simple for loop it will take hours to compare all 854 collection that are contained in pCol.
Here is my code:
Function CompareCollections(ByVal pCol As Collection) As Collection
Dim outer As Long
Dim inner As Long
'collections that will be compared to each other
Dim inCol As Collection
Dim outCol As Collection
'collection used for return values
Dim retCol As Collection
'result of single comparison
Dim res As CompResult
'comparison variables
Dim iIdx As Long
Dim oIdx As Long
Dim same As Long
Set retCol = New Collection
For outer = 1 To pCol.Count - 1
Set outCol = pCol(outer)
For inner = outer + 1 To pCol.Count
Set inCol = pCol(inner)
Set res = New CompResult
res.LeftTable = outCol(1) 'index 1 contains a header
res.RightTable = inCol(1)
'compare the two collections <== PART I WANT TO SPEED UP
same = 0
For oIdx = 2 To outCol.Count 'starting with 2 to ignore the header
For iIdx = 2 To inCol.Count
If inCol(iIdx) = outCol(oIdx) Then same = same + 1
Next iIdx
DoEvents
Next oIdx
res.Result1 = same / (outCol.Count - 1)
res.Result2 = same / (inCol.Count - 1)
retCol.Add res
Set res = Nothing
Set inCol = Nothing
DoEvents
Next inner
Set outCol = Nothing
DoEvents
Next outer
Set CompareCollections = retCol
End Function
I really hope you guys can help me.
EDIT:
The CompResult class is a simple structure, because I could not add a custom type to the collection:
Private mLeftTable As String
Private mRightTable As String
Private mResult1 As Double
Private mResult2 As Double
Public Property Get LeftTable() As String
LeftTable = mLeftTable
End Property
Public Property Let LeftTable(value As String)
mLeftTable = value
End Property
Public Property Get RightTable() As String
RightTable = mRightTable
End Property
Public Property Let RightTable(value As String)
mRightTable = value
End Property
Public Property Get Result1() As Double
Result = mResult1
End Property
Public Property Let Result1(value As Double)
mResult1 = value
End Property
Public Property Get Result2() As Double
Result = mResult2
End Property
Public Property Let Result2(value As Double)
mResult2 = value
End Property
A first tip: try to precalculate outCol.Count, inCol.Count and pCol.Count in order to avoid unnecessary calculations.
Second tip: if in your object CompResult the res.Result1 and res.Result2 are integers, use "\" instead of "/".
Third tip: try to use integers instead of long values wherever you can.
Fourth tip: try to replace for loops by a "for each" loops when looping for every column. It seems a little faster.
A last tip might be transform collections (ranges) in arrays and iterate through them, as it seems faster than iterate through ranges.

Do I need an array, class, dictionary, or collection?

I am not sure what the best option is for what I'm trying to do. Currently, I'm using a 3D array to hold these values, but I am just now learning about dictionaries, classes, and collections in VBA and can't determine if any of those would be better or more useful for what I'm trying to do.
I get a new spreadsheet of data every month, and I need to loop through cells looking for a number, and replace another cell's data based on that number. I.E. (all in Col. A)
4323
4233
4123
4343
4356
3213
In column B, I need to put a corresponding country. If the first two digits are 43, the cell to the right should be "Germany" and then in col. C, "DEU". If the two numbers are 41, then the col. B cell should be "USA", and in C, "USA"...etc. etc.
Currently, I'm setting up a 3D array (psuedo code):
myArray(0,0) = 43
myArray(0,1) = "Germany"
myArray(0,2) = "DEU"
myArray(1,0) = 41
myArray(1,1) = "United States"
myArray(1,2) = "USA"
etc. etc.
Then, I have a loop going through all the cells and replacing the information.
Would a class perhaps be better? I could then do something like create a cntry. Code, cntry.Country, cntry.CountryAbbrev and use those to refer to "43", "Germany", and "DEU"
(again, psuedo code):
num = left("A1",2)
'then here, somehow find the num in cntry.Code list - will need to work out how
Cells("B1").Value = cntry.Country
Cells("C1").Value = cntry.CountryAbbrev
...
As for Dictionaries, I think that won't work, as (AFAIK) you can only have one key per entry. So I could do the country number ("43") but set only either the Country name or Country Abbreviation - but not both....correct?
Does this question make sense? Is using a class/dictionary overkill on something like this? Would a collection be best?
Thanks for any advice/guidance!
Class Module is the answer. It's always the answer. Code is code and there's almost nothing you can do in a class module that you can't do in a standard module. Classes are just a way to organize your code differently.
But the next question becomes how to store your data inside your class module. I use Collections out of habit, but Collection or Scripting.Dictionary are your best choices.
I'd make a class called CCountry that looks like this
Private mlCountryID As Long
Private msCode As String
Private msFullname As String
Private msAbbreviation As String
Public Property Let CountryID(ByVal lCountryID As Long): mlCountryID = lCountryID: End Property
Public Property Get CountryID() As Long: CountryID = mlCountryID: End Property
Public Property Let Code(ByVal sCode As String): msCode = sCode: End Property
Public Property Get Code() As String: Code = msCode: End Property
Public Property Let Fullname(ByVal sFullname As String): msFullname = sFullname: End Property
Public Property Get Fullname() As String: Fullname = msFullname: End Property
Public Property Let Abbreviation(ByVal sAbbreviation As String): msAbbreviation = sAbbreviation: End Property
Public Property Get Abbreviation() As String: Abbreviation = msAbbreviation: End Property
Then I'd make a class called CCountries to hold all of my CCountry instances
Private mcolCountries As Collection
Private Sub Class_Initialize()
Set mcolCountries = New Collection
End Sub
Private Sub Class_Terminate()
Set mcolCountries = Nothing
End Sub
Public Property Get NewEnum() As IUnknown
Set NewEnum = mcolCountries.[_NewEnum]
End Property
Public Sub Add(clsCountry As CCountry)
If clsCountry.CountryID = 0 Then
clsCountry.CountryID = Me.Count + 1
End If
mcolCountries.Add clsCountry, CStr(clsCountry.CountryID)
End Sub
Public Property Get Country(vItem As Variant) As CCountry
Set Country = mcolCountries.Item(vItem)
End Property
Public Property Get Count() As Long
Count = mcolCountries.Count
End Property
You see that CCountries is merely a Collection at this point. You can read more about that NewEnum property at http://dailydoseofexcel.com/archives/2010/07/09/creating-a-parent-class/
Then I'd put all my country stuff in a Table and read that table into my class. In CCountries
Public Sub FillFromRange(rRng As Range)
Dim vaValues As Variant
Dim i As Long
Dim clsCountry As CCountry
vaValues = rRng.Value
For i = LBound(vaValues, 1) To UBound(vaValues, 1)
Set clsCountry = New CCountry
With clsCountry
.Code = vaValues(i, 1)
.Fullname = vaValues(i, 2)
.Abbreviation = vaValues(i, 3)
End With
Me.Add clsCountry
Next i
End Sub
I'd need a way to find a country by one of its properties
Public Property Get CountryBy(ByVal sProperty As String, ByVal vValue As Variant) As CCountry
Dim clsReturn As CCountry
Dim clsCountry As CCountry
For Each clsCountry In Me
If CallByName(clsCountry, sProperty, VbGet) = vValue Then
Set clsReturn = clsCountry
Exit For
End If
Next clsCountry
Set CountryBy = clsReturn
End Property
Then I'd run down my list of numbers and put the codes next to them
Sub FillCodes()
Dim clsCountries As CCountries
Dim rCell As Range
Dim clsCountry As CCountry
Set clsCountries = New CCountries
clsCountries.FillFromRange Sheet1.ListObjects("tblCountries").DataBodyRange
For Each rCell In Sheet2.Range("A3:A5").Cells
Set clsCountry = Nothing
Set clsCountry = clsCountries.CountryBy("Code", CStr(rCell.Value))
If Not clsCountry Is Nothing Then
rCell.Offset(0, 1).Value = clsCountry.Fullname
rCell.Offset(0, 2).Value = clsCountry.Abbreviation
End If
Next rCell
End Sub
Other than defining where the codes I'm looping through are, I don't really need any comments. You can tell what's going on my the name of the object and the properties or methods. That's the payoff for the extra work in setting up class modules - IMO.
You can have a dictionary of objects or dictionaries.
VBA has several methods to store data:
a Dictionary
a Collection
an array (matrix) variable
an ActiveX ComboBox
an ActiveX ListBox
a Userform control ComboBox
a Userform control ListBox
a sortedlist
an arraylist
I suggest you to read the following article:
http://www.snb-vba.eu/VBA_Dictionary_en.html

Lotusscript: Use variable as array name so can apply function in a loop

I am not sure if I phrased the question well. Here is what I want to accomplish.
My agent builds a series of 25 or so arrays. Arr1() and Arr(2) etc. They are dynamic as I do not know how many items they will contain.
The agent must apply several functions to each array. One simple one is a bubble sort.
So I have 25 lines of code like this:
Call bub_sort(Arr1)
Call bub_sort(Arr2)
etc.
For each function I have 25 lines of code like that (or similar code).
Over time I will add additional arrays and possibly different functions.
Seems like it would be better to Load a List or Array of the array names, and then iterate over that for the functions, like so
'Sort Arrays
ForAll lst In lstGrpNme
Call bub_sort(lst)
End Forall
However, the code of course doesn't work as I am passing the string, not an array.
How can I get around this?
I fear that I will have to make a class?
You can create an Variant array of all arrays and iterate through all with Forall:
Dim Array1(10) As String
Array1(0) = "one"
...
Dim Array2(10) As String
Array2(0) = "two"
...
Dim AllArrays(25) As Variant
AllArrays(0) = Array1
AllArrays(1) = Array2
...
Forall Array In AllArrays
If Not Isempty(Array) Then
If Ubound(Array) > 0 Then
Print(Array(0)) ' prints every array's first element
Call bub_sort(Array)
End If
End If
End Forall
You can omit the two If lines if you are sure that every element of AllArrays is filled and that every array has at least one element.
You could use a List instead of an array in a similar way too. Just change this one Dim line:
Dim AllArrays List As Variant
Instead of numbers 0, 1, 2, ... you could give arrays names and access them later with the name.
Const ARRAY_ONE = 0
Const ARRAY_TWO = 1
AllArrays(ARRAY_ONE) = Array1
AllArrays(ARRAY_TWO) = Array2
...
Dim TmpArray As Variant
TmpArray = AllArrays(ARRAY_ONE)
TmpArray(0) = "xxx"
AllArrays(ARRAY_ONE) = TmpArray
This is a typical example of when a class would be very useful.
I fear that I will have to make a class?
Don't be afraid, classes are actually very easy. I wrote two blog entries about this a while back, take a look if you like:
http://blog.texasswede.com/object-oriented-lotusscript-for-beginners-part-1/
http://blog.texasswede.com/object-oriented-lotusscript-for-beginners-part-2/
Since you think you might add more functions later, you should build this as a class.
Then you could do something like this:
Set myArray = New MyArrayClass(arr1,arr2)
Call myArray.bubbleSort
If you want literally to pass a string as array name then you can use Execute statement. For this you must put all your array variables to (Declarations) section of your agent.
Here is example:
`Declarations
Dim tempArray As Variant 'This is temp array for performing operations
Dim array0 As Variant
Dim array1 As Variant
'... and so on
Sub Initialize
'...
Dim arrayNames() As String
Redim array0(2) As Integer
Redim array1(1) As Integer
array0(0) = 0
array0(1) = 1
array0(2) = 2
array1(0) = 3
array1(1) = 4
Redim arrayNames(1) As String
arrayNames(0) = "array0"
arrayNames(1) = "array1"
'Do something with all arrays
Forall arrayName In arrayNames
Call GetArray(arrayName)
Call DoSomethingWithArray(tempArray)
Call SetArray(arrayName)
End Forall
'...
End Sub
'Put array to tempArray
Sub GetArray(arrayName As String)
Execute "tempArray = " & arrayName$
End Sub
'Put tempArray to array
Sub SetArray(arrayName As String)
Execute arrayName$ & " = tempArray"
End Sub
'Some function
Sub DoSomethingWithArray(array As Variant)
For index% = 0 To Ubound(array)
array(index%) = array(index%) + 1
Next
End Sub
I would use a list of Arrays and/or a Class like this:
%REM
Description: NOT TESTET! JUST FOR DEMONSTRATION!
%END REM
Public Class ArrayHandler
Private ArrayList() As Variant
Private ArrayListCounter As Long
%REM
Sub New
Description: Constructor
%END REM
Public sub New(firstArray As Variant)
ArrayListCounter = 0
ReDim Preserve ArrayList(ArrayListCounter) As Variant
ArrayList(ArrayListCounter) = firstArray
End Sub
%REM
Sub addArray
Description: self Explaining... ;)
%END REM
Public Sub addArray(nexArray As Variant)
ArrayListCounter = ArrayListCounter + 1
ReDim Preserve ArrayList(ArrayListCounter) As Variant
ArrayList(ArrayListCounter) = nexArray
End Sub
%REM
Sub bub_sort_allArrays
Description: The Magic Function! ;-)
%END REM
Public Sub bub_sort_allArrays()
ForAll arrs In ArrayList
Call bub_sort(arrs)
End ForAll
End Sub
%REM
Sub bub_sort
Description: YOUR FUNCTION!
%END REM
Public Sub bub_sort(Arr As Variant)
'//-- YOUR CODE GOES HERE
End Sub
End Class
I hope this will help you. :)
EDIT:
A second more fitting idea, maybe...:
Public Class ArrayHandler
Private ArrayList List As Variant
%REM
Sub New
Description: Constructor
%END REM
Public sub New(firstArray As Variant, firstArrayName As String)
ArrayList(firstArrayName) = firstArray
End Sub
%REM
Sub addArray
Description: self Explaining... ;)
%END REM
Public Sub addArray(nexArray As Variant, nextArrayName As String)
ArrayList(nextArrayName) = nexArray
End Sub
%REM
Sub bub_sort_allArrays
Description: The Magic Function! ;-)
%END REM
Public Sub bub_sort_allArrays()
ForAll arrs In ArrayList
Call bub_sort(ListTag(arrs))
End ForAll
End Sub
%REM
Sub bub_sort
Description: YOUR FUNCTION!
%END REM
Public Sub bub_sort(Arr As Variant)
'//-- YOUR CODE GOES HERE
End Sub
End Class

Resources