Solved

Use a string to refered to an object

Posted on 2000-05-11
4
117 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

21 Experts available now in Live!

Get 1:1 Help Now