×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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?

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
.
.

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

(OP)
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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources