Solved

Use a string to refered to an object

Posted on 2000-05-11
4
118 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
  • 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 70 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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now