Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Use a string to refered to an object

Posted on 2000-05-11
4
Medium Priority
?
124 Views
Last Modified: 2010-05-02
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

0
Comment
Question by:Nothing99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2801834
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
0
 
LVL 7

Accepted Solution

by:
Vbmaster earned 280 total points
ID: 2802127
You can set the function to return a object, like this..

Function test(p1 as integer) As Object

  Select Case p1
  Case 1
    Set test = object1
  ...
  Case n
    Set test = objectn
  End select

End function

This will make code like test(2).name work the way you want.

Any reason why you are not using a control array? To control a control array you create one object on the form and then copy'n'paste the object, VB will automatically create a control array. Whenever you want to access a object you use code like name_of_the_objects(index).
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2803106
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?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2803914
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question