Operate on a custom VBA Class Object
Operate on a custom VBA Class Object
(OP)
Think of this small example.
I want to write my own data type class to handle numerical data of a different type, such as with complex numbers or high-precision floating point numbers. Is it possible to write a class that allows you to simply swap out the datatype in the above code (from "Double" to "clsSuperDuperDataType" and have something that works out of the box, working with VBA's built-in arithmetic operators and even with literal declarations? Doing a "find and replace" on existing code is where I'd like to go with this.
Thanks.
Durette
CODE
Dim dblA as Double
Dim dblB as Double
Dim dblC as Double
dblA = 2
dblB = 4
dblC = dblA + dblB
MsgBox dblC
'Returns 6
Dim dblB as Double
Dim dblC as Double
dblA = 2
dblB = 4
dblC = dblA + dblB
MsgBox dblC
'Returns 6
Thanks.
Durette





RE: Operate on a custom VBA Class Object
http://www.cpearson.com/excel/DefaultMember.aspx
A default member allows me to declare the value, but I still don't see how that would allow me to operate in a non-trivial fashion (such as with matrices or complex numbers).
RE: Operate on a custom VBA Class Object
RE: Operate on a custom VBA Class Object
But I'm not sure that what you want is possible (if I have understood it correctly). For instance, if you had a complex number class, using two doubles for input, the only way you could work with that using the built in Excel facilities would be to convert the number to a text string, then use the complex number functions via a worksheetfunction call. That would, I think, be very slow and inefficient. The alternative would be to use something like the Alglib library, which includes complex number arithmetic, and should work well with a custom class.
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Operate on a custom VBA Class Object