LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Variant vs Double for functions where data could be "null"

I am creating a number of calculation functions which will exist
within a class object. The properties used in the function may not
have been given a value so I need an efficient way to determine this
and acting accordingly. I can see about 3 options - all with
drawbacks - so am hoping someone could give me some guidance on which
is good practice and of course if there is a better alternative! I
wonder if vb.net offers any insights given that it doesn't support
variants? My options a

1) Declare variables as variant and initialise to Null.
Now I can simply carry out the calculation and if any of the variables
is null the function will return Null. Very straight foward but I
would normally steer away from using variants if possible.

2) Declare variables as double and initialise to a value representing
no value (eg. -999)
Now I can test each of the variables before doing the calculation.
This itself seems to be somewhat of an overhead though and also means
that when I call other properties (which are themselves calculations)
I need to pass them first to a variable and test them rather than
using them directly in my function. If I could use zero as my "no
value" constant it would work in much the same way as Null for
variants but for division would give an error.

3) Create my own variable type as follows
Type Number
val as double
hasval as integer '0 if no, 1 if yes
end Type

Now I can multiply .hasval for each property and if any of them are 0
it will return 0.

Very interested to hear how others have handled this issue since it
must have come up before.

Thanks a lot,
Andrew

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Functions for "current" & "previous" month to calculate data Priss Excel Worksheet Functions 11 April 15th 08 06:24 PM
Null, "null", vbNull, vbNullString, vbEmpty [email protected] Excel Programming 2 July 25th 06 01:28 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
cells formatted to tick when text value "Y" if or null if "N" Jay Excel Discussion (Misc queries) 7 January 13th 06 09:16 AM
"IF"- "THEN" type Formula based on Null value Jay Excel Worksheet Functions 8 November 17th 05 09:05 AM


All times are GMT +1. The time now is 04:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"