D
D
Dreadd2014-11-10 09:10:30
Visual Basic
Dreadd, 2014-11-10 09:10:30

Custom data types - how to get value by field name?

Hello!
There is Excel and VBA, there is a custom data type, something like this:

public type MyType
  varA as A
  varB as B
  varC as C
end type

There is a variable, type MyType
Further, I have a variable in which the line a certain line ("varA", for example) lies. The task is to get the value of the field whose name is in the string. Something like
s = "varB"
print(varofMyType.$s)

How to do it? The task has grown from a laboratory task, where there is an array of variables of some user type, which is filled with data from a sheet. This is hard work but good. And then, according to the condition of the problem, you need to "write subroutines for sorting the array by field A, field B and field C".
Itching in my ear from such horror does not allow me to copy-paste one procedure three times with hardcoded field names. It is impossible to use matrices instead of types, sort by Excel functions, and so on.
I ask for your advice! Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question