Link to home
Start Free TrialLog in
Avatar of Nothing99
Nothing99

asked on

Use a string to refered to an object

First, sorry for my poor english... My native language is french.

Now my question:

I need to have a function that return a string. Something like this:

Function test(p1 as integer) as String
  Select Case p1
    Case 1
      test = "object1"
    ...
    Case n
      test = "objectn"
  End select
End function

So if i use "test(2).name" i will access the name property of object2.

Sorry if it's confuse.

Vincent

Avatar of AzraSound
AzraSound
Flag of United States of America image

the way you have the function set up it will return a single value for test...all you should have to do is return test and youll get the object from the select case statement

Dim str As String
str = test(3)
Msgbox str
ASKER CERTIFIED SOLUTION
Avatar of Vbmaster
Vbmaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
he says he wants to return a string...maybe he means this:

Function test(p1 as integer) as String
  Select Case p1
    Case 1
      test = object1.name
    ...
    Case n
      test = objectn.name
  End select
End function


now test will return the name of whichever object is selected according to the p1 value that is passed to the function.  let us know if we're reading your question correctly.


however this wouldnt make much sense to have a control array as they all bear the same name (different indexes)
how does the p1 parameter reference a particular object?  what is the correlation between the two?
Avatar of Guy Hengel [angelIII / a3]
Public Function Text(p1 as Integer) as String
Text = me.Controls("object" & p1).Name
End Function

This may be what you are looking for, Me is referring to the Form