Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you pass the name of a type member to a function?

Status
Not open for further replies.

Nojj

Computer
Apr 8, 2003
10
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
.
.
 
Replies continue below

Recommended for you

Oops : Just realised the example I gave has an easy solution. What I really need to do is something like this:

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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor