|
-
Nov 9th, 2008, 06:45 AM
#1
Thread Starter
PowerPoster
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
-
Nov 20th, 2008, 11:48 AM
#2
Re: about list property
What are the errors that you are getting and what lines or code are causing them?
-
Nov 21st, 2008, 03:57 PM
#3
Thread Starter
PowerPoster
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
-
Dec 4th, 2008, 09:50 AM
#4
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.
-
Dec 5th, 2008, 05:12 PM
#5
Thread Starter
PowerPoster
Re: about list property
 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
-
Dec 5th, 2008, 06:37 PM
#6
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.
-
Dec 5th, 2008, 07:01 PM
#7
Thread Starter
PowerPoster
Re: about list property
 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.
-
Dec 6th, 2008, 01:09 AM
#8
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.
-
Dec 6th, 2008, 04:20 AM
#9
Thread Starter
PowerPoster
Re: about list property
 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
-
Dec 6th, 2008, 02:05 PM
#10
Re: about list property
 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.
-
Dec 6th, 2008, 02:32 PM
#11
Thread Starter
PowerPoster
Re: about list property
 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
-
Dec 6th, 2008, 02:56 PM
#12
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.
-
Dec 6th, 2008, 03:08 PM
#13
Thread Starter
PowerPoster
Re: about list property
 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
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
|