Results 1 to 7 of 7

Thread: [RESOLVED] [VB6] how to make an array property persistence?

  1. #1

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

    Resolved [RESOLVED] [VB6] how to make an array property persistence?

    i have 1 property array:
    Code:
    Public Property Get ObjectSelected(ByRef intList As Integer) As String
        On Error GoTo erro
        ObjectSelected = strObjectNames(intList)
        Exit Property
    erro:
        ObjectSelected = ""
    End Property
    
    Public Property Let ObjectSelected(ByRef intList As Integer, strObjectName As String)
        If intList = 0 Then
            ReDim strObjectNames(0 To intList)
        Else
            ReDim Preserve strObjectNames(0 To intList)
        End If
        strObjectNames(intList) = strObjectName
        PropertyChanged "ObjectSelected"
    End Property
    i try using these way:
    Code:
    SelectedControls(0).ObjectSelected a, lstControls.List(i)
    but give an error: "run-time error '450': wrong number of arguments or invalid property assigment".
    it's my first time doing the property type(arrays). can anyone help me?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

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

    Re: [VB6] how to make an array property persistence?

    my problem was these line
    Code:
    SelectedControls(0).ObjectSelected(a) = lstControls.List(i)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3

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

    Re: [VB6] how to make an array property persistence?

    now how can i make it persistence?
    i try it, but i only do it for the 1st element
    Code:
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
       ObjectSelected(0) = PropBag.ReadProperty("ObjectSelected", "")
    end sub
    
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
      PropBag.WriteProperty "ObjectSelected", ObjectSelected(0), ""
    end sub
    i try using a loop, but without results
    can anyone help?
    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: [VB6] how to make an array property persistence?

    The only arrays VB can store are byte arrays. But since your array is string, there are at least 3 ways you can persist them, easy, hard, inefficient.

    1. Easy. Join() the strObjectNames array on a delimiter when writing. Split() the array on same delimiter when reading. By using Join() the array becomes one long string.

    2. Hard. Sum each strObjectNames array item's length, create a byte array of that length. Then move each strObjectNames array item into the byte array. Can use StrConv() to move item to a temp byte array then use CopyMemory to transfer that temp array to your array you will be writing to the property bag.

    3. Inefficient. Loop thru each array item and write it as a separate property, i.e.,
    PropBag.WriteProperty "Item0", strObjectNames(0), ""
    PropBag.WriteProperty "Item1", strObjectNames(1), ""
    Last edited by LaVolpe; Dec 3rd, 2009 at 09:16 PM.
    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,960

    Re: [VB6] how to make an array property persistence?

    Quote Originally Posted by LaVolpe View Post
    The only arrays VB can store are byte arrays. But since your array is string, there are at least 3 ways you can persist them, easy, hard, inefficient.

    1. Easy. Join() the strObjectNames array on a delimiter when writing. Split() the array on same delimiter when reading. By using Join() the array becomes one long string.

    2. Hard. Sum each strObjectNames array item's length, create a byte array of that length. Then move each strObjectNames array item into the byte array. Can use StrConv() to move item to a temp byte array then use CopyMemory to transfer that temp array to your array you will be writing to the property bag.

    3. Inefficient. Loop thru each array item and write it as a separate property, i.e.,
    PropBag.WriteProperty "Item0", strObjectNames(0), ""
    PropBag.WriteProperty "Item1", strObjectNames(1), ""
    i don't understand the 1st way
    i understand the 3rd way, but i try do it without sucess
    i know that i start in 0 item, but if i don't have any or the next item, i recive ""(empty)(is the good way to finish 1 loop with these array).
    i will try again, the loop, then i will tell you something
    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: [VB6] how to make an array property persistence?

    Quote Originally Posted by joaquim View Post
    i don't understand the 1st way
    Code:
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
      PropBag.WriteProperty "ListItems", Join(strObjectNames(), Chr$(8)), ""
    End sub
    
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
       strObjectNames() = Split(PropBag.ReadProperty("ListItems", ""), Chr$(8))
    End sub
    The above will combine your string array using backspace/chr$(8) as a delimiter. Since it is now a single string item, you can save it easily. When time to read it back, it is read and then Split() using backspace as the delimiter
    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,960

    Re: [VB6] how to make an array property persistence?

    Quote Originally Posted by LaVolpe View Post
    Code:
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
      PropBag.WriteProperty "ListItems", Join(strObjectNames(), Chr$(8)), ""
    End sub
    
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
       strObjectNames() = Split(PropBag.ReadProperty("ListItems", ""), Chr$(8))
    End sub
    The above will combine your string array using backspace/chr$(8) as a delimiter. Since it is now a single string item, you can save it easily. When time to read it back, it is read and then Split() using backspace as the delimiter
    thanks it's working 100% good
    now i can build my object list colision
    thanks
    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