Click to See Complete Forum and Search --> : [RESOLVED] [VB6] how to make an array property persistence?
joaquim
Dec 3rd, 2009, 04:06 PM
i have 1 property array:
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:
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
joaquim
Dec 3rd, 2009, 04:31 PM
my problem was these line;)
SelectedControls(0).ObjectSelected(a) = lstControls.List(i)
joaquim
Dec 3rd, 2009, 04:34 PM
now how can i make it persistence?
i try it, but i only do it for the 1st element:(
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
LaVolpe
Dec 3rd, 2009, 06:23 PM
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), ""
joaquim
Dec 4th, 2009, 09:20 AM
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;)
LaVolpe
Dec 4th, 2009, 09:29 AM
i don't understand the 1st way:(
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
joaquim
Dec 4th, 2009, 12:10 PM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.