Solved

Default values in class

Posted on 2002-03-26
5
155 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
  • 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 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

26 Experts available now in Live!

Get 1:1 Help Now