How do you pass the name of a type member to a function?
How do you pass the name of a type member to a function?
(OP)
Hi Guys. This one is driving me mad. I'm trying to write a function which receives a user-defined type member name (not its value). How do you pass the name of a type member to a function? Obviously you can pass it as a string but then how do you use it?
This should make things clear:
Private Type MyType
x1 as integer
x2 as single
End type
Dim MyData as MyType
.
.
x = MyFunction(MyData.x2) ' this passes the value (which is not what I want)
MyFunction must be able to do his :
Public Function MyFunction (whatever)
whatever = 1.23 ' save value in MyData.x2
.
.
This should make things clear:
Private Type MyType
x1 as integer
x2 as single
End type
Dim MyData as MyType
.
.
x = MyFunction(MyData.x2) ' this passes the value (which is not what I want)
MyFunction must be able to do his :
Public Function MyFunction (whatever)
whatever = 1.23 ' save value in MyData.x2
.
.





RE: How do you pass the name of a type member to a function?
x = MyFunction("x2")
Public Function MyFunction (whatever)
Dim Yourdata as MyType
YourData.whatever = 1.23 ' must do the same as YourData.x2 = 1.23
.
.
Believe me, I have a good reason for wanting to do this!