|
-
Dec 3rd, 2009, 05:06 PM
#1
Thread Starter
PowerPoster
[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
-
Dec 3rd, 2009, 05:31 PM
#2
Thread Starter
PowerPoster
Re: [VB6] how to make an array property persistence?
my problem was these line
Code:
SelectedControls(0).ObjectSelected(a) = lstControls.List(i)
-
Dec 3rd, 2009, 05:34 PM
#3
Thread Starter
PowerPoster
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
-
Dec 3rd, 2009, 07:23 PM
#4
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.
-
Dec 4th, 2009, 10:20 AM
#5
Thread Starter
PowerPoster
Re: [VB6] how to make an array property persistence?
 Originally Posted by LaVolpe
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
-
Dec 4th, 2009, 10:29 AM
#6
Re: [VB6] how to make an array property persistence?
 Originally Posted by joaquim
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
-
Dec 4th, 2009, 01:10 PM
#7
Thread Starter
PowerPoster
Re: [VB6] how to make an array property persistence?
 Originally Posted by LaVolpe
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|