CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2001
    Posts
    16

    Help me with object variable

    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



  2. #2
    Join Date
    Sep 2001
    Posts
    49

    Re: Help me with object variable

    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)



  3. #3
    Join Date
    Dec 2000
    Posts
    29

    Re: Help me with object variable

    What did you put in obj?
    You should write a little bit of code for us!


  4. #4
    Join Date
    Sep 2001
    Posts
    16

    Re: Help me with object variable

    Here is the code:


    Dim obj as Object

    set obj = TextBox1.Object
    set TextBox2.Object = obj ' Got error here




    Thanks.


  5. #5
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Help me with object variable

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  6. #6
    Join Date
    Dec 2000
    Posts
    29

    Re: Help me with object variable

    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


  7. #7
    Join Date
    Sep 2001
    Posts
    16

    Re: Help me with object variable

    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?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured