So you can have some fun, I'm letting you input your own set of numbers for the
functions to chew on. You'll need to use commas to delimit your list so it knows
where to split it up. If you don't enter any valid numbers, the functions will
return Null which won't show up as anything in the browser.
This time we've got a pair of functions: Min() and Max(). Anyone want to guess what
they do? That's right boys and girls... they return the lowest and highest numeric
values in an array. The idea for the sample was actually suggested to me by a
visitor to our site. Most likely someone just like you!
The implementation is pretty straight-forward, but I've thrown in a couple
interesting things I should probably mention. The request for this function pair
asked that the functions be able to handle being passed Nulls, so I made sure they
could. In fact they should handle just about anything as long as it's in an array.
They'll ignore strings and such, but should keep chugging along looking for numbers.
In terms of Null, I also use it as my return value if there's no valid input. As
such, It'd probably be in your best interest to use IsNull() to check for this
before you use the return value for anything important!
A quick definition of Null for those non-programmers among us:
A value indicating that a variable contains no valid data. Null is the result of:
An explicit assignment of Null to a variable.
Any operation between expressions that contain Null.
Microsoft's words... not mine! We need to watch our copyright issues these days!
There's one other thing that you might find odd at first glance. I use a double
float instead of an integer, long int, or single to store my temporary value. This
is mainly so the script will handle very small numbers, very large numbers and
fractions. If I had simply user an integer, you'd get errors whenever you used
numbers larger than 32,767 or anything that wasn't a whole number. This should
alleviate those issues and make the functions pretty robust.
For those of you unfamiliar with doubles:
Variant Sub-type Double
Contains a double-precision, floating-point number in the range
-1.79769313486232E308 to -4.94065645841247E-324 for negative values;
4.94065645841247E-324 to 1.79769313486232E308 for positive values.
That was Microsoft again... yeah like I'd know those numbers without looking them up.
I may be a geek, but I'm not that bad!