Results 1 to 21 of 21

Thread: Using Objects

  1. #1

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Using Objects

    Using Objects in UserControls
    Is there any way to let the user interact with an object in it?
    Last edited by Mc Brain; Oct 26th, 2002 at 01:06 PM.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Could you explain a little more?

    You can allow access to private objects through a property if that is what you mean...
    VB Code:
    1. Public Property Get SomeObject() As SomeObject
    2.     Set SomeObject = mSomeObject
    3. End Property
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I mean something like this:

    VB Code:
    1. Public Function TV() As TreeView
    2.     Set TV = TreeView
    3. End Function
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I don't know if it works the same way with functions vs properties, I would use a property. It should allow that.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I'd tried your code as well... but didn't work.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    What happens? Can you supply the code?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    All you have to do is create an instance of the object in your class and return a ref to the calling code. I would use a property get.

  8. #8

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    ---------------------------
    Microsoft Visual Basic
    ---------------------------
    Compile error:

    Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as fields of public user defined types
    ---------------------------
    Aceptar Ayuda
    ---------------------------
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  9. #9

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by Lethal
    All you have to do is create an instance of the object in your class and return a ref to the calling code. I would use a property get.
    How would you do that?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  10. #10
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by Mc Brain
    ---------------------------
    Microsoft Visual Basic
    ---------------------------
    Compile error:

    Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as fields of public user defined types
    ---------------------------
    Aceptar Ayuda
    ---------------------------
    Are you using an actual Treeview, or something of your own? If its your own class, then set the Instancing property to 5 MultiUse and it should work.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  11. #11

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I'm using a TreeView, and would like to let the user access their methods and properties without any coding.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  12. #12
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Here's an example:

    Code:
    Option Explicit
    Public Name As String
    
    Public Property Get Clone() As MyObject
        Dim clsClone As New MyObject
        clsClone.Name = Me.Name
        Set Clone = clsClone
    End Property

  13. #13

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I don't think that would let me do what I'm after....
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  14. #14
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by Mc Brain
    I'm using a TreeView, and would like to let the user access their methods and properties without any coding.
    Well, then its a bit tricky, you'll need to make the property type an Object, then to get the intellisense and all that, you can set a treeview variable to the property
    VB Code:
    1. 'In the Usercontrol
    2. Public Property Get TV() As Object
    3.   Set TV = Treeview1
    4. End Property
    5.  
    6. 'On a form
    7.  
    8. Private Sub Command1_Click()
    9. Dim tvw as Treeeview 'Only need for intellisense purposes
    10.  
    11.   Set tvw = Usercontrol1.TV
    12.  
    13.   Call tvw.Nodes.Add (Text:="Hello")
    14.  
    15. End Sub

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  15. #15
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    For a treeview, swap out the textbox code:

    Code:
    Option Explicit
    Private myBox As TextBox
    
    Public Property Let MyTextBox(txtExample As TextBox)
        Set myBox = txtExample
    End Property
    
    Public Property Get MyTextBox() As TextBox
        Set MyTextBox = myBox
    End Property

  16. #16

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Damned!! I was trying to avoid that! I mean, it won't be that intuitive for the UserControl's user.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  17. #17

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by Lethal
    For a treeview, swap out the textbox code:

    Code:
    Option Explicit
    Private myBox As TextBox
    
    Public Property Let MyTextBox(txtExample As TextBox)
        Set myBox = txtExample
    End Property
    
    Public Property Get MyTextBox() As TextBox
        Set MyTextBox = myBox
    End Property
    Am I not following you? I don't think that code would work. The TreeView is on the UserControl. I would like to let the user Interact with it.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  18. #18
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Ah..got ya...i read the question 2 quick...then, you are left with the code crypt provided or just expose methods through your code that automate what you want to provide for the user.

  19. #19

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    This is what I'm after... I want the user to be able to load and remove items as if he/she had a TreeView on his/her form.
    Attached Files Attached Files
    Last edited by Mc Brain; Oct 26th, 2002 at 02:07 PM.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  20. #20

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Sorry... I've uploaded the file again because the first one didn't work.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  21. #21

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Ok... here's the version with all the "View" (ViewTree, ViewAddress, ViewWebStyle) properties coded. I guess I should have told (just in case) that the MS Windows Common Controls have to be loaded.
    Attached Files Attached Files
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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