Solved

Creating a property

Posted on 2002-03-30
20
223 Views
Last Modified: 2010-05-02
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?  
0
Comment
Question by:newvber
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
20 Comments
 

Author Comment

by:newvber
ID: 6907533
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
 
LVL 44

Expert Comment

by:bruintje
ID: 6907569
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
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6907643
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:newvber
ID: 6907705
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
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6907752
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
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6907790
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
 

Author Comment

by:newvber
ID: 6907791
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
 

Author Comment

by:newvber
ID: 6907792
Sorry, COAtheGREAT, I didn't see your second post.  Give me a minute to try it out.
0
 

Author Comment

by:newvber
ID: 6907811
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
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6907820
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
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6907844
does it working ?
0
 

Author Comment

by:newvber
ID: 6907847
The x = pcPath doesn't work.  It's always empty.  
0
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6907858
show me all code
0
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6907861
show me all code
0
 

Author Comment

by:newvber
ID: 6907869
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
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6907875
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
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6907881
second error
Private pcPath
it should be
Private pcPath as string
and same for plActive
0
 

Author Comment

by:newvber
ID: 6907883
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
 
LVL 1

Accepted Solution

by:
COAtheGREAT earned 50 total points
ID: 6907896
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
 

Author Comment

by:newvber
ID: 6907910
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question