Creating a property

I'm usually developing in FoxPro where creating a property is interactive.  I'm creating an ActiveX control in VB and I need to provide a property for the user to set.  This property will be a certain path.  These Property Get & Let confuse me.  Can someone please give me the steps to accomplish this?  
newvberAsked:
Who is Participating?
 
COAtheGREATConnect With a Mentor Commented:
dont be sory it is normal, next it is not

Private Sub oStarImage_ReadProperties(PropBag As PropertyBag)
   pcPath = PropBag.ReadProperty("cPhoto_Path")
   plActive = PropBag.ReadProperty("lActive")
End Sub

Private Sub oStarImage_WriteProperties(PropBag As PropertyBag)
   PropBag.WriteProperty "cPhoto_Path", pcPath
   PropBag.WriteProperty "lActive", plActive
End Sub

it is

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

   pcPath = PropBag.ReadProperty("cPhoto_Path", "")
   plActive = PropBag.ReadProperty("lActive", False)

End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

   PropBag.WriteProperty "cPhoto_Path", pcPath, ""
   PropBag.WriteProperty "lActive", plActive, False

End Sub

and now work :)
0
 
newvberAuthor Commented:
This is the code I have so far:
private pcPath

Public Property Get cPhoto_Path() As String
    cPhoto_Path = pcPath
End Property

Public Property Let cPhoto_Path(ByVal vNewValue As String)
    pcPath = vNewValue
End Property

I get no errors, but when I enter a value in the property, it does not remain during run-time.
0
 
bruintjeCommented:
Hi newvber,

-better make that declare

private pcPath as String

-have tried to run it like ?

msgbox yourcontrol.cPhoto_Path
yourcontrol.cPhoto_Path = "test"
msgbox yourcontrol.cPhoto_Path

:O)Bruintje
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
COAtheGREATCommented:
Bouth previous answer are OK and you shuld use both. First you use when you nead to know when property is changed and do some actions as response.

In that case you use Property Let if the property is variable or Property Set if the property is object.

If you want property to be read only then you write only Property Get and dont wtite let or set, and if you want property to be read-write then you shuld write get and let or set.

If you dont nead to know when property changes and want property to be read-write then you declare Public variable, and it is seen outside as property.
0
 
newvberAuthor Commented:
COAtheGREAT, I tried your suggestion and I'm still having the same problem of setting the property in development and not seeing the value I set during run-time.  I don't know what step I am missing.
0
 
COAtheGREATCommented:
I think this is what you need:
Use PropertyBag to save value of the properties betwen design time ond run time

Public Property Let bgColor(vNewValue As OLE_COLOR)

    Text1.BackColor = vNewValue
    PropertyChanged "bgColor"

End Property

Public Property Get bgColor() As OLE_COLOR

    bgColor = Text1.BackColor

End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

    Text1.BackColor = PropBag.ReadProperty("bgColor")

End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

    PropBag.WriteProperty "bgColor", Text1.BackColor

End Sub
0
 
COAtheGREATCommented:
Try this

private pcPath

Public Property Get cPhoto_Path() As String
   cPhoto_Path = pcPath
End Property

Public Property Let cPhoto_Path(ByVal vNewValue As String)
   pcPath = vNewValue
   PropertyChanged "cPhoto_Path"
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
   pcPath= PropBag.ReadProperty("cPhoto_Path")
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
   PropBag.WriteProperty "cPhoto_Path", pcPath
End Sub
0
 
newvberAuthor Commented:
Is it handled the same way when you're not assigning the property value to an object?  I want to use the value in a method.  Do I need to use an object in order to have the value available to me?
0
 
newvberAuthor Commented:
Sorry, COAtheGREAT, I didn't see your second post.  Give me a minute to try it out.
0
 
newvberAuthor Commented:
COAtheGreat, I'm working at being a super pain in the *****.  When I'm in another method I want to get the value from that property.  I've tried the following:

x = pcPath
x = cPhoto_path
x = user_control1.cphoto_path
x = oStarImage.cphoto_path   (This is the name of my user control)

Have you ever worked this hard for 50 points before?
0
 
COAtheGREATCommented:
if it is method within control then
x = pcPath
if it is from outside then
x = oStarImage.cphoto_path

I dont have much time so be quick, asking is no problem just time :)
0
 
COAtheGREATCommented:
does it working ?
0
 
newvberAuthor Commented:
The x = pcPath doesn't work.  It's always empty.  
0
 
COAtheGREATCommented:
show me all code
0
 
COAtheGREATCommented:
show me all code
0
 
newvberAuthor Commented:
The save() is where I'm trying to see what the developer assigned to the property at design time.

Option Explicit
Private pcPath
Private plActive

Private Sub Command1_Click()
    Save "star.jpg"
End Sub

Public Sub Save(tcFileName As String)
Dim x As String

x = pcPath

End Sub


Private Sub oStarImage_ReadProperties(PropBag As PropertyBag)
    pcPath = PropBag.ReadProperty("cPhoto_Path")
    plActive = PropBag.ReadProperty("lActive")
End Sub

Private Sub oStarImage_WriteProperties(PropBag As PropertyBag)
    PropBag.WriteProperty "cPhoto_Path", pcPath
    PropBag.WriteProperty "lActive", plActive
End Sub

Public Property Get cPhoto_Path() As String
    cPhoto_Path = pcPath
End Property

Public Property Let cPhoto_Path(ByVal vNewValue As String)
    pcPath = vNewValue
    PropertyChanged "cPhoto_Path"
End Property

Private Property Get lActive() As Variant
    lActive = plActive
End Property

Private Property Let lActive(ByVal vNewValue As Boolean)
    plActive = vNewValue
    PropertyChanged "lActive"
End Property
0
 
COAtheGREATCommented:
Private Property Get lActive() As Variant
   lActive = plActive
End Property

Private Property Let lActive(ByVal vNewValue As Boolean)
   plActive = vNewValue
   PropertyChanged "lActive"
End Property

this is big error so control cant be placed on form property cant be variant and bool at the same time. Chose
0
 
COAtheGREATCommented:
second error
Private pcPath
it should be
Private pcPath as string
and same for plActive
0
 
newvberAuthor Commented:
Sorry about that.  I was in the middle of trying to add a different property when I checked EE.  I remembered you wanted things fast, so I just copied & pasted as soon as I could, before checking the new stuff.
0
 
newvberAuthor Commented:
Beyond Excellent!  Went way beyond call of duty for a meezely 50 points.  If I had more points, I'd certainly give them to COAtheGREAT!
0
All Courses

From novice to tech pro — start learning today.