Results 1 to 13 of 13

Thread: about list property

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    about list property

    i'm using VB6...
    i'm trying build a list property(is my 1st list property):
    Code:
    Dim objName() As String
    
    Public Property Get ObjectsCollision(ObjectIndex As Long) As String
        If strFileName = "" Or blnDestroyed = True Then Exit Property
        ObjectsCollision = objName(ObjectIndex)
    End Property
    
    Public Property Let ObjectsCollision(ObjectName As String, ObjectIndex As Long)
        If strFileName = "" Or blnDestroyed = True Then Exit Property
        If ObjectIndex > objName.Count Then ReDim Preserve objName(ObjectIndex)
        objName(i) = ObjectName
        PropertyChanged "ObjectsCollision"
    End Property
    i have some errors in code, can anyone help me in code?
    how can i use it in readproperties and writeproperties UC events?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: about list property

    What are the errors that you are getting and what lines or code are causing them?

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: about list property

    these one works:
    Code:
    Public Property Get ObjectName(ByVal objIndex As Integer) As String
        If objIndex >= 0 And objIndex <= UBound(objName) Then
            ObjectName = objName(objIndex)
        End If
    End Property
    
    Public Property Let ObjectName(ByVal objIndex As Integer, ByVal vNewval As String)
        ReDim Preserve objName(objIndex)
        objName(objIndex) = vNewval
        PropertyChanged "ObjectName"
    End Property
    but i have 2 problems:
    1-how put these property in readproperties and writeproperties UC events?
    2-how can i show it in a listbox(like list property in listbox control), but in list property?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: about list property

    Regarding showing it in a listbox on the property sheet, you can't without adding some complicated code which can be found on vbAccelerator. Otherwise, you can use a propertypage and listbox to add the items in design time.
    http://www.vbaccelerator.com/home/vb...se/article.asp

    Now for storing your string array, this can be a bit complicated but not too much. I think there are only 3 choices:
    1. Store each item in its own property...
    -- PropBag.WriteProperty "Count", UBound(Array)+1
    -- PropBag.WriteProperty "Item" & x, Array(x), looping through each array item

    2. You can join the string array to a single string variable and save it that way:
    Code:
    PropBag.WriteProperty "ItemList", Join(objName(), vbNullChar)
    
    and to read them
    objName() = Split(PropBag.ReadProperty("ItemList",""), vbNullChar)
    3. The only arrays vb can store in a propertybag are byte arrays, you can convert your string array to byte array, but the code can be a little complex. If you wish to go this route, I can post an example.
    Last edited by LaVolpe; Dec 4th, 2008 at 10:40 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: about list property

    Quote Originally Posted by LaVolpe
    Regarding showing it in a listbox on the property sheet, you can't without adding some complicated code which can be found on vbAccelerator. Otherwise, you can use a propertypage and listbox to add the items in design time.
    http://www.vbaccelerator.com/home/vb...se/article.asp

    Now for storing your string array, this can be a bit complicated but not too much. I think there are only 3 choices:
    1. Store each item in its own property...
    -- PropBag.WriteProperty "Count", UBound(Array)+1
    -- PropBag.WriteProperty "Item" & x, Array(x), looping through each array item

    2. You can join the string array to a single string variable and save it that way:
    Code:
    PropBag.WriteProperty "ItemList", Join(objName(), vbNullChar)
    
    and to read them
    objName() = Split(PropBag.ReadProperty("ItemList",""), vbNullChar)
    3. The only arrays vb can store in a propertybag are byte arrays, you can convert your string array to byte array, but the code can be a little complex. If you wish to go this route, I can post an example.
    i'm sorry, can you explain better the 2nd choice?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: about list property

    What is there to explain? Use VB's Join() function to combine the string array to a single string whch can be stored. Then after reading it, use Split() to put it an array. Try it.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: about list property

    Quote Originally Posted by LaVolpe
    What is there to explain? Use VB's Join() function to combine the string array to a single string whch can be stored. Then after reading it, use Split() to put it an array. Try it.
    ok.. i just copy the lines. the array still with no number of items, but i can't see the list property(in VB6 window property)... why?
    Last edited by joaquim; Dec 5th, 2008 at 07:07 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: about list property

    You won't see a list box in the property sheet. You will have to supply a property page for users to add list items or require users to add the list items during runtime only.

    The Split() & Join() functions allow you to save your string array to the propertybag.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: about list property

    Quote Originally Posted by LaVolpe
    You won't see a list box in the property sheet. You will have to supply a property page for users to add list items or require users to add the list items during runtime only.

    The Split() & Join() functions allow you to save your string array to the propertybag.
    i'm sorry, but is my objective. like in vbaccelerator(but i need more things here, because i have an error. but i will see it). my objective is put a property like List property in ListBox ActiveX control.
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: about list property

    Quote Originally Posted by joaquim
    i'm sorry, but is my objective. like in vbaccelerator(but i need more things here, because i have an error. but i will see it). my objective is put a property like List property in ListBox ActiveX control.
    thanks
    VB's propertysheet is a simple owner-drawn listbox. The List property of a listbox, is created on the fly by VB. It is a textbox that is simply overlayed on the propertysheet. When it loses focus, it goes away. The little ... & down-arrow buttons you see on some properties? That is an simple owner-drawn button.

    Remember this. The propertysheet is just a custom-drawn listbox, nothing more. All the other stuff that appears: ..., droparrow, textboxes to enter properties, combobxes are done by VB.

    Therefore, one could get creative and subclass the propertysheet and add their own API-created listbox to imitate VB's list property, but that is a ton of work that will only fit VB. What if your OCX is used in MSAccess or .Net or some other language? You won't have a VB property sheet to subclass and the only way a user can enter data would be a PropertyPage that you created. Therefore, I recommend creating a PropertyPage so users can add/remove listitems from your OCX.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: about list property

    Quote Originally Posted by LaVolpe
    VB's propertysheet is a simple owner-drawn listbox. The List property of a listbox, is created on the fly by VB. It is a textbox that is simply overlayed on the propertysheet. When it loses focus, it goes away. The little ... & down-arrow buttons you see on some properties? That is an simple owner-drawn button.

    Remember this. The propertysheet is just a custom-drawn listbox, nothing more. All the other stuff that appears: ..., droparrow, textboxes to enter properties, combobxes are done by VB.

    Therefore, one could get creative and subclass the propertysheet and add their own API-created listbox to imitate VB's list property, but that is a ton of work that will only fit VB. What if your OCX is used in MSAccess or .Net or some other language? You won't have a VB property sheet to subclass and the only way a user can enter data would be a PropertyPage that you created. Therefore, I recommend creating a PropertyPage so users can add/remove listitems from your OCX.
    yes i will put it in propertypage, i'm work on it too.
    thanks for everything.
    i will ignore my list objetive and use in propertypage.
    i have a question. i have the property has you know... but see the code.
    Code:
    Public Property Get ObjectName(ByVal objIndex As Integer) As String
        If objIndex >= 0 And objIndex <= UBound(objName) Then
            ObjectName = objName(objIndex)
        End If
    End Property
    
    Public Property Let ObjectName(ByVal objIndex As Integer, ByVal vNewval As String)
        ReDim Preserve objName(objIndex)
        objName(objIndex) = vNewval
        PropertyChanged "ObjectName"
    End Property
    
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
        objName() = Split(PropBag.ReadProperty("ObjectName", ""), vbNullChar)
    End Sub
    
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
        PropBag.WriteProperty "ObjectName", Join(objName(), vbNullChar)
    End Sub
    my question is: like is these property i can use it and save the data with propertypage without a problem?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: about list property

    No, there are a couple of ways of doing this though. I think the easiest way is this.

    You will have a listbox on the property page, yes?
    1. In your propertypage add this:
    Code:
    ' Declarations section
    Private theControl As UserControl ' << change UserControl to your UserControl's Name (i.e., ucSpriteControl or whatever)
    
    ' the Apply event
    Set theControl = SelectedControls(0)
    Set theControl.ppgUpdateObjectName = List1 ' propertypage's ListBox
    
    ' the SelectionChanged event
        Dim X As Long
        List1.Clear ' property page's listbox
        Set theControl = SelectedControls(0)
        For X = 0 To theControl.Count - 1 ' some property that says how many you have
            List1.AddItem theControl.ObjName(X)
        Next
    
    ' whenever you add/delete/change items in List1, ensure you set
    PropertyPage.Changed = True
    2. In your UserControl create a new property:
    Code:
    Friend Property Set ppgUpdateObjectName(theList As ListBox)
        Dim X As Long
        If theList.ListCount = 0& Then
            Erase objName()
        Else
            ReDim objName(0 To theList.ListCount-1)
            For X = 0 To theList.ListCount-1
                objName(x) = theList.List(x)
            Next
        End If
        PropertyChanged "ObjectName"
    End Property
    Why use Friend above? This will make the property unavailable to users if the usercontrol is compiled to an OCX. You may also want to go to the attributes window & set the property as hidden. View uc code then select menu: Tools|Procedure Attributes.

    3. Open your usercontrol in design view. Find PropertyPages in the propertysheet. Select your new propertysheet. This will add the Custom property to your usercontrol. Users can now access it by opening hte Custom property or right clicking on uc and selecting Properties.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: about list property

    Quote Originally Posted by LaVolpe
    No, there are a couple of ways of doing this though. I think the easiest way is this.

    You will have a listbox on the property page, yes?
    1. In your propertypage add this:
    Code:
    ' Declarations section
    Private theControl As UserControl ' << change UserControl to your UserControl's Name (i.e., ucSpriteControl or whatever)
    
    ' the Apply event
    Set theControl = SelectedControls(0)
    Set theControl.ppgUpdateObjectName = List1 ' propertypage's ListBox
    
    ' the SelectionChanged event
        Dim X As Long
        List1.Clear ' property page's listbox
        Set theControl = SelectedControls(0)
        For X = 0 To theControl.Count - 1 ' some property that says how many you have
            List1.AddItem theControl.ObjName(X)
        Next
    
    ' whenever you add/delete/change items in List1, ensure you set
    PropertyPage.Changed = True
    2. In your UserControl create a new property:
    Code:
    Friend Property Set ppgUpdateObjectName(theList As ListBox)
        Dim X As Long
        If theList.ListCount = 0& Then
            Erase objName()
        Else
            ReDim objName(0 To theList.ListCount-1)
            For X = 0 To theList.ListCount-1
                objName(x) = theList.List(x)
            Next
        End If
        PropertyChanged "ObjectName"
    End Property
    Why use Friend above? This will make the property unavailable to users if the usercontrol is compiled to an OCX. You may also want to go to the attributes window & set the property as hidden. View uc code then select menu: Tools|Procedure Attributes.

    3. Open your usercontrol in design view. Find PropertyPages in the propertysheet. Select your new propertysheet. This will add the Custom property to your usercontrol. Users can now access it by opening hte Custom property or right clicking on uc and selecting Properties.
    i'm sorry but i have 1 more simple way, but i will need methods instead properties(but can save the values).
    after i finish these, i will tell you something.
    i'm realy sorry bored you and thanks for help me... thanks my friend
    VB6 2D Sprite control

    To live is difficult, but we do it.

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