Solved

Creating a property

Posted on 2002-03-30
20
220 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now