I'm still somewhat new to object style programming (as will become
evident), using VBA in Excel 2000 to automate some previously manual
functions.
I've defined a class module so that I can create objects that reflect
data gathered in web inquiries. The module has a bunch of Get/Let
routines such as this pair:
Private m_dYield As Double
Public Property Let SetYield(ByRef NewYield As Double)
m_dYield = NewYield
End Property
Public Property Get Yield() As Double
Yield = m_dYield
End Property
The problem is that zero is a valid assignment for most of these
properties, and yet I need to distinguish between a property that's been
"set" to zero versus one that has never been initialized, yet has a
default value of zero by virtue of the dimension statement. IsNull and
IsEmpty functions apparently only work with variant data types, besides
which, I dimly recall assorted VB instructors who were emphatically
against their use.
There has to be a simple solution to what must be a very common problem,
but it's got me stumped. Any suggestions are sincerely appreciated... 2 7657
"Enigman O'Maly" <No***@Home.com> wrote in message
news:jb********************************@4ax.com... I'm still somewhat new to object style programming (as will become evident), using VBA in Excel 2000 to automate some previously manual functions.
I've defined a class module so that I can create objects that reflect data gathered in web inquiries. The module has a bunch of Get/Let routines such as this pair:
Private m_dYield As Double
Public Property Let SetYield(ByRef NewYield As Double) m_dYield = NewYield End Property
Public Property Get Yield() As Double Yield = m_dYield End Property
The problem is that zero is a valid assignment for most of these properties, and yet I need to distinguish between a property that's been "set" to zero versus one that has never been initialized, yet has a default value of zero by virtue of the dimension statement. IsNull and IsEmpty functions apparently only work with variant data types, besides which, I dimly recall assorted VB instructors who were emphatically against their use.
There has to be a simple solution to what must be a very common problem, but it's got me stumped. Any suggestions are sincerely appreciated...
First, you Let and Get should probably match (i.e. both be Yield).
For many such properties I would agree that explicit data types are better and
faster than variants. But I hardly ever say never.
There are various ways to handle your issue. If the value of yield should be=0, you can initialize m_dYield to -1 in the class Initialize event, and tell
that way. Otherwise, you might use a second Boolean variable, m_bYieldSet, which
will initially be false, and which you make true inside of the property let
procedure for yield:
Public Property Let Yield(ByRef NewYield As Double)
m_dYield = NewYield
m_bYieldSet = True
End Property
On Fri, 10 Oct 2003 19:33:00 -0700, "Steve Gerrard"
<no*************@comcast.net> wrote: "Enigman O'Maly" <No***@Home.com> wrote in message news:jb********************************@4ax.com.. . I'm still somewhat new to object style programming (as will become evident), using VBA in Excel 2000 to automate some previously manual functions.
I've defined a class module so that I can create objects that reflect data gathered in web inquiries. The module has a bunch of Get/Let routines such as this pair:
Private m_dYield As Double
Public Property Let SetYield(ByRef NewYield As Double) m_dYield = NewYield End Property
Public Property Get Yield() As Double Yield = m_dYield End Property
The problem is that zero is a valid assignment for most of these properties, and yet I need to distinguish between a property that's been "set" to zero versus one that has never been initialized, yet has a default value of zero by virtue of the dimension statement. IsNull and IsEmpty functions apparently only work with variant data types, besides which, I dimly recall assorted VB instructors who were emphatically against their use.
There has to be a simple solution to what must be a very common problem, but it's got me stumped. Any suggestions are sincerely appreciated...
First, you Let and Get should probably match (i.e. both be Yield). For many such properties I would agree that explicit data types are better and faster than variants. But I hardly ever say never. There are various ways to handle your issue. If the value of yield should be=0, you can initialize m_dYield to -1 in the class Initialize event, and tell that way. Otherwise, you might use a second Boolean variable, m_bYieldSet, which will initially be false, and which you make true inside of the property let procedure for yield: Public Property Let Yield(ByRef NewYield As Double) m_dYield = NewYield m_bYieldSet = True End Property
Thanks, Steve; I guess I'll convert the data elements to variants, since
the IsEmpty function will do what I want. Also, thanks for the
suggestion about Let/Get routine names. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: SteveS |
last post by:
What's the difference in using the private variable as opposed to the actual
property in a class module? Which is better or more efficient? (
LoginObject.Save (_loginName) or LoginObject.Save...
|
by: Dr John Stockton |
last post by:
It has appeared that ancient sources give a method for Numeric Date
Validation that involves numerous tests to determine month length;
versions are often posted by incomers here. That sort of code...
|
by: WindAndWaves |
last post by:
Dear All
Can you tell me why you use a class module???
Thank you
Nicolaas
---
|
by: Johnny M |
last post by:
using Access 2003
Pardon the subject line, but I don't have a better word for this
strange
behavior (or behavior I don't understand!!!)
I have a class module named DepreciationFactor. One of...
|
by: Gustaf Liljegren |
last post by:
Here's a very general programming question. I often wonder where to put the
data validation when adding data to a struct or class, using its
constructor.
Suppose for example I got a class called...
| |
by: Tom |
last post by:
I have written a validatedTextBox class which inherits
from textBox. I've added code which validates the input
text using the onValidation event.
The problem I have is that when I have input...
|
by: JonathanOrlev |
last post by:
Hello everyone,
I have a newbe question:
In Access (2003) VBA, what is the difference between a Module and a
Class Module in the VBA development environment?
If I remember correctly, new...
|
by: ADezii |
last post by:
The motivation for this Tip was a question asked by one of our Resident Experts, FishVal. The question was: How to Declare Default Method/Property in a Class Module? My response to the question was...
|
by: c2015 |
last post by:
I need help with some VB code. I will keep it generic and clear as possible.
I have two forms lets call Form1 and Form2
I have a class module (CM) and a sub class module (SCM) instantiated in...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |