Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object into a variable... 1

Status
Not open for further replies.

swisslog

Programmer
Jul 11, 2002
20
CH
I thought that the following statements were trivial:


Dim cbox As ComboBox
cbox = my_control_box1

'my_control_box1 is a recognized ComboBox in a UserForm

I want to pass the cbox variable to a function declared like this:


Public Function load_values(Acbox As ComboBox)



The problem: in the debugger, I can see that VBA gives a string value to my_control_box1...
Exactly as if the first statement was: cbox = my_control_box.Value !
This is not what I want. I want to refer to the object, not to a content of that object.

Could anybody indicate me how to load an object type in a variable?

Thank you!

Bart




 
Thank you segmentationfault. I tried that too, with no sucess, since 'my_control_box1' is a string for VBA (i.e, on execution time, the debugger does not show me an object for 'my_control_box1' but a string!)

Our local time is 4.20PM. I would be so happy if I could go for the week-end after having found out what is wrong!!

Thanks again
 
Oh, my fault, I didn't read your problem carefully enough.

As far as resolving string data to be used as a variable within the program, it isn't going to happen. (I think Java has a mechanism to do this, but if so, it is very unique). The problem is that variable names are simply there for the convenience of the programmer. To the executable, they are all replaced by memory locations. Therefore, you can't type "myVariable" into an input box and directly get the value of such a variable - it doesn't exist in that form in that context.

You'll have to fix this problem at the source. It seems your my_combo_box1 is picking up the .Name rather than a true reference to the object. Is my_combo_box1 actually the name of the object in question? If so, that's really bizarre, and my best idea at the moment would be to resolve the name better, ie "UserForm1.my_combo_box1"
 
Yes, we are on the same frequency! I also tried your last suggestion and that gives exactly the same result.

That what I try to do works with other 4GL environnements.

But it seems that VBA interprets the my_combo_box1 reference to the actual active string value in state of to the object??!!

I will reconsider the question on Monday...

Thanks and have a nice week-end
 
Ah, that would probably work. I wasn't aware that a name could be passed to return the object.
 
Set Cbox = Me.Controls("my_control_box1")
is an excellent idea. Thank you JohnYingling.
I also tried Set Cbox = Me.my_control_box1
works also.

When I call the function
Public Sub load_values(ByRef cbox As ComboBox)
like this
load_values(Cbox)
I get the error: "Object required"

In the debugger, I can see that Cbox is now a real object.

What do I misunderstand?
 
I can't belive it!
That was the only problem!
I transformed the function to a sub in one of my many tries.

Thanks a lot

Bart

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top