Click to See Complete Forum and Search --> : Help me with object variable
Invoker
October 2nd, 2001, 08:12 AM
Hello,
I need your help in the next situation:
I have object variable (as Object) which holds TextBox1.Object
I need some method or something else to load control holded in this object variable to form.
If I place TextBox2 on the form and then try to do following:
set TextBox2.Object = obj 'my object var
I will get error Type mismatch.
Help me please.
Thanks
DeafBug
October 2nd, 2001, 01:38 PM
I am not clear on your intentions but it seems to me that there is no Text1.Object. How did you declare the obj value as? Not sure if you mean set obj = Text1
The Type mismatch happen because the two objects are different types. Unless you convert a type, the types always have to be the same. For example, you can assign an integer to an integer. But assigned a long to an integer will raise the type mismatch error. You will need to convert it like this IntValue = CInt(lngValue)
dosyl
October 2nd, 2001, 02:16 PM
What did you put in obj?
You should write a little bit of code for us!
Invoker
October 3rd, 2001, 09:54 AM
Here is the code:
Dim obj as Object
set obj = TextBox1.Object
set TextBox2.Object = obj ' Got error here
Thanks.
Cakkie
October 3rd, 2001, 10:13 AM
I'm affraid what you are trying to do is impossible. When assigning Text1 to the object, you actually assing a refference to the object instead of the object. When you then try to pass the refference on to a real object, you get an error. To see what I mean, try this:
set obj = Text1
obj.Text = "SomeText"
You will see that the text of Text1 has changed, what prooves that you are actually dealing with refferences instead of real objects.
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
dosyl
October 3rd, 2001, 12:36 PM
Do this instead:
Dim obj as TextBox
set obj = TextBox1
set TextBox2 = obj
I hope it is that you want!
P.S. I suggest to use another variable instead of obj, something like: txt1
Invoker
October 3rd, 2001, 03:02 PM
Thanks, but it is not what I want.
When I wrote my code, I just simple it for you and others.
My I HAVE TO using obj (as Object) variable. Because I receive this object from Persitent Storage File. I could write 'ActiveX.Object', but receive only to Object variable.
...
'Writes object to Persistent Storage
Stream.WriteObject TextBox1.Object
...
'Receive object from Persistent Storage
Dim obj as Object
Stream.ReadObject obj
'I could not write TextBox1.Object instead of 'obj', because 'Object' property is read-only
Thats why I need the way to do something with this Object variable.
I receive obj ('Object/TextBox' if check watches) how can I load this Object/ActiveX to the form?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.