-
I am trying to use assign a object to a object variable
I can't understand
when I should use new keyword and when I shouldn't
what is the differance 1 and 2
1 . set myobject=new myobject1
2 . set myobject=myobject1
my second question related first
I am designing a activex component that have a property
holding an object named returnobject.
mycontrol.ReturnObject = Text1
If IsObject(mycontrol.ReturnObject) Then
MsgBox "object"
Else
MsgBox "not object"
End If
msgbox displaying "not object"
why ? I sent a object to returnobject.
How can I correct it. how can I assign a value
to text1 with using my returnobject variable.
can anyone help me?
-
1. Instances an object of class named "myobject1"
2. Sets an object reference to "myobject1" object
I think youre a bit confuse so i'll explain:
YOu use New keyword to create a new object of a class.
New Myclass, will return an instance of Myclass
New Form1, will return a new form1.
YOU use Set keyword to assign a a object reference, for instace:
Code:
Dim a as Form1 ' Declares an object reference, no form is created yet
Dim a as New Form1 ' Declares and assign an object reference with a new form1.
Set a = New Form1 ' Creates a new instance of form1 and puts it in a.
Set b = a ' Sets the object reference of a to b, you can now acces the new form from both a and b.
SEt a = Nothing 'will clear a object reference, will also delete an object if it's the last reference.
UNload a ' will delete the object.
[/code]
-
Second thing, did you declare the public object variable as object/textbox or did you declare is as a variant? Because a variable is variant by default. Change it to object or textbox. It may also be the other problem, you have to use set, to assign a object reference, ifyou omit it then Let will be default, assigning the objects default property instead, that's the text in the text1 textbox. So you should use:
Code:
set mycontrol.ReturnObject = Text1
If you want to keep the variant.