0

I have a class with, let's say, 5 properties and same amount of functions that return regular data types. I have prepared a class factory that takes all of them (properties) and returns an object. I'm wondering if it is possible to pass these properties using the class factory directly from the sheet and later use such created instance as an argument to other UDFs that require that class.

=someFunction(Factory(1,2,3,4,5))
GSerg
  • 76,472
  • 17
  • 159
  • 346
  • As far as I know, you cannot do that. The value returned from `Factory` will be converted to `CVErr(xlErrValue)`, and that is what `someFunction` is going to receive. – GSerg Jan 19 '20 at 16:12
  • So the only solution is to create as many UDFs as functions within class, hence each time create the same class object? – Michał Polok Jan 19 '20 at 16:22
  • Or pass serialized version of the class instance, e.g. a json string. Rehydrate to actual instance inside functions. – GSerg Jan 19 '20 at 16:24
  • Could you provide me an example? – Michał Polok Jan 19 '20 at 16:27
  • 1
    `{"a":1, "b":2, "c":3, "d":4, "e":5}` and https://stackoverflow.com/q/6627652/11683. `` and https://stackoverflow.com/q/11305/11683. – GSerg Jan 19 '20 at 16:28
  • What is `someFunction` - another custom UDF? If you have Factory() return a hashed reference to the created instance (or just concatenate the arguments with `~` for example), and store the created instance in a global (eg) Dictionary then `someFunction` can reference the object from that Dictionary using the supplied key. – Tim Williams Jan 19 '20 at 17:30
  • Yes, some function is another udf that streams method from created class. – Michał Polok Jan 19 '20 at 21:07

0 Answers0