Solved

Default values in class

Posted on 2002-03-26
5
161 Views
Last Modified: 2010-05-02
Probably a real easy question...

If I want a property of my class to have a default value what is the proper way to implement?  Is there a default setting of a let statement?  is it best to check for ismissing in any functions that use the property?

0
Comment
Question by:dcaparaso
[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
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
COAtheGREAT earned 50 total points
ID: 6896729
Use Class_Initialize event to set default values

Private Sub Class_Initialize()

  myProp1=...

End Sub
0
 
LVL 2

Expert Comment

by:ronenr
ID: 6896730
You can have a member variable where you store the default value, this value can be set in the initialize procedure of your class.

eg

private mValue as string

public property let Value(byval val as string )
   mValue
end property

public property get Value() as string
 Value = mValue
end property


Private Sub Class_Initialize()
   mValue="test string"
end sub
0
 
LVL 2

Expert Comment

by:ronenr
ID: 6896741
Opps a fix

public property let Value(byval val as string )
  mValue=val
end property
0
 

Author Comment

by:dcaparaso
ID: 6896928
and then if a client sets a property that was first set during intialize event the variable is replaced with the client's value - correct?

0
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6896931
correct :)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

728 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