Replies: 4 comments
-
So my concern is less about the effort required to make such a class, but rather would it bring any benefit? So I'd be totally happy if there is a use case. So far here I've seen 2:
In this case you don't need an array at all, and using
So this to me sounds like something I envision
With stdTable.CreateFromName("Test")
'Update column Energy from values in other columns
.update("Energy", stdLambda.Create("0.5 * $1.mass * $1.velocity ^ 2"))
'Update relativistic velocities with relativistic Kinetic energy
.where(stdLambda.Create("$2.velocity > 0.5 * $1").bind(c)) _
.update("Energy", stdLambda.Create("((1 - $2.velocity ^ 2 / $1 ^ 2) ^ (-0.5) -1) * $2.mass * $1 ^ 2").bind(c))
'Read-write Access to values if required
Msgbox .values(1,1) 'First row, first column
.values(1,1) = "hello world"
'Essentially looping through queries of this table
Dim row as stdTable
For each row in .rows
Debug.Print row.values(1,1)
next
'Get a detatched copy of a query (preventing `update` from updating the original table.
set detatched = .query(stdLambda.Create("$1.mass < 100")).detatch()
detatched.update("Comment", "Tiny")
'Save to another table
Call detatched.saveToRange(Sheet1.Range("A1"))
'in an ideal world joins would be great too
End With In this instance you can very quickly update a whole column. If you have a reference to a row, you can update that row too. If you could give examples where you can do things with a 2d array which you can't do with something like this, that'd be good to know about :) |
Beta Was this translation helpful? Give feedback.
-
I have built a class which probably does pretty much what @lopperman is referring to: a 2 dimensional data table that allows you to read a csv file, load data from an Excel range or add data manually. It provides navigation and data access functions and basic indexing (for now unique indices only - based on a HashTable class from Francesco Balena). You can find it in the following repository. The main use case I developed it for, is to be able to work with tabular data without the need of relying on Excel Ranges during computation. It allows to store nested structures as well, as you can have a given item to be an object itself, so you can nest data tables and create more complex structures. Probably you could get to the same results with stdArray, but (at least for me) this class has proven very useful, in particular to manage table like data which makes sense to keep togehter. To give you some use cases, you can load data from various sources, do lookups merge/enhance data, calculate new fields, do a distinct selection over a subset of fields and continue whatever you need to do on this subset of data. In more practical terms, I have built some more advanced NLP applications involving text cleansing, stemming, vectorization, similarity (distance) calculation and clustering based on a distance matrix, all using this class to store the various data sets needed in the process. Just to give you an idea how such a data structure can be used. A maybe more simple use case is a performance measurement class I have built, which uses the data table to store the raw data. This class can be found here. The approach of both classes is clearly not the same as your stdVBA collection of classes, this is just to illutrate the potential use cases for a 2d array. |
Beta Was this translation helpful? Give feedback.
-
Hi @dangrazh and thanks for the input. First let me say this looks like a great class and really useful tool for VBA devs! Well done and thanks for making it Open Source :)
Indeed, as discussed in my response to the initial post, I can totally see the use case of a class for handling tables/tabular data. But in these cases I'd much prefer a tool explicitely for this. I.E. I was really looking for other use cases other than handling tabular data (or data with a very specific structure). |
Beta Was this translation helpful? Give feedback.
-
@dangrazh, I took a look at your Data-Table. Agree with @sancarn that you did a nice job on that. Unfortunately it would be a massive undertaking to modify that to work with Mac (All my VBA code is PC and Mac compatible). If did fork the repo and make cHashTable compatible with Mac OS -- if you wnat to open it up for Pull request, I could submit that -- or just copy the 'CopyMemory' section with the change. Kind of tangential to this thread, but I did some testing with cHashTable. I also created a custom hash class a while back, but I never implemented the ability to remove items (no need so far, but I'm sure others would appreciate it). cHashTable does an excellent job adding items, but is very slow with retrieval. I wanted to make sure I was retrieving items in the most optimal way -- could you let me know if I'm not? Below is the code I ran against your cHashTable, and against my pbHash. If you want to test the pbHASH.cls, there are not dependencies, except you will need to add this Type to a common module:
FETCH PERFORMANCE DIFFERENCE
|
Beta Was this translation helpful? Give feedback.
-
@lopperman and I were discussing in reddit DM's:
Beta Was this translation helpful? Give feedback.
All reactions