Value too big or too small

G

Gordon Bentley-Mix

I'm sure there's an easy answer to this, but I'm having a senior moment. Is
there a better way to determine if a number is within a range of acceptable
values other than using something like this?

If myNumber < 1 Or myNumber > 100 Then
MsgBox "Don't be a dork!"
End If

Dunno why but I have this feeling that there is and I'm just missing it.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
M

macropod

Hi Gordon,

I suppose you could use:
If Abs(MyNumber -50.5) > 49.5 Then MsgBox "Don't be a dork!"
 
G

Gordon Bentley-Mix

Hmm... not quite what I had in mind, but thanks anyway.

A couple of days later and my mind is not so mushy; however, I still can't
see a solution. It just seems a bit clunky to do it the way I am, but if it
works and it's all I've got...

At least this got me thinking about ways to improve things around where I'm
doing this comparison. I'm trying to make sure that the user enters a valid
day of the month. The code (which I inherited) just looks to see if the value
is between 1 and 31 without regard to the month. This got me thinking about
ways to vary the range of acceptable values according to the month selected,
and I thought I had a solution - a variable for the uppermost acceptable
value, a Case statement to set it and a function to take in the value and do
the validation accordingly.

HOWEVER...

I'm now questioning the reasoning behind entering the month and day
separately in the first place, as the full date is required anyway. I suspect
the UserForm was designed this way because the previous developer wanted to
be able to insert the various parts of the date into the document separately
(e.g. "the 10th day of September, 2006") and didn't know how to parse the
date. I'm MUCH smarter than that! <g> I'll just use IsDate to validate the
value and then pick it apart afterwards.

So not a wasted effort since it did get me to re-examine the business rule
behind the functionality.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


macropod said:
Hi Gordon,

I suppose you could use:
If Abs(MyNumber -50.5) > 49.5 Then MsgBox "Don't be a dork!"

--
Cheers
macropod
[MVP - Microsoft Word]


Gordon Bentley-Mix said:
I'm sure there's an easy answer to this, but I'm having a senior moment. Is
there a better way to determine if a number is within a range of acceptable
values other than using something like this?

If myNumber < 1 Or myNumber > 100 Then
MsgBox "Don't be a dork!"
End If

Dunno why but I have this feeling that there is and I'm just missing it.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
T

Tony Jollans

Basically, no, there isn't a better way. There may be a different way but,
essentially, you must check both ends of the range and your code is as good
as any other.
 
M

macropod

Hi Gordon,

FWIW, if you forced the user to choose a year & month before the day, you could limit the day choices via a dropdown or spinner.

--
Cheers
macropod
[MVP - Microsoft Word]


Gordon Bentley-Mix said:
Hmm... not quite what I had in mind, but thanks anyway.

A couple of days later and my mind is not so mushy; however, I still can't
see a solution. It just seems a bit clunky to do it the way I am, but if it
works and it's all I've got...

At least this got me thinking about ways to improve things around where I'm
doing this comparison. I'm trying to make sure that the user enters a valid
day of the month. The code (which I inherited) just looks to see if the value
is between 1 and 31 without regard to the month. This got me thinking about
ways to vary the range of acceptable values according to the month selected,
and I thought I had a solution - a variable for the uppermost acceptable
value, a Case statement to set it and a function to take in the value and do
the validation accordingly.

HOWEVER...

I'm now questioning the reasoning behind entering the month and day
separately in the first place, as the full date is required anyway. I suspect
the UserForm was designed this way because the previous developer wanted to
be able to insert the various parts of the date into the document separately
(e.g. "the 10th day of September, 2006") and didn't know how to parse the
date. I'm MUCH smarter than that! <g> I'll just use IsDate to validate the
value and then pick it apart afterwards.

So not a wasted effort since it did get me to re-examine the business rule
behind the functionality.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


macropod said:
Hi Gordon,

I suppose you could use:
If Abs(MyNumber -50.5) > 49.5 Then MsgBox "Don't be a dork!"

--
Cheers
macropod
[MVP - Microsoft Word]


Gordon Bentley-Mix said:
I'm sure there's an easy answer to this, but I'm having a senior moment. Is
there a better way to determine if a number is within a range of acceptable
values other than using something like this?

If myNumber < 1 Or myNumber > 100 Then
MsgBox "Don't be a dork!"
End If

Dunno why but I have this feeling that there is and I'm just missing it.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
G

Gordon Bentley-Mix

Thanks Tony. Maybe I'll write my own function to do this - if I ever find
myself in the situation when I need to be doing a heap of "in the range"
checks.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
G

Gordon Bentley-Mix

Possible and pretty much what I had in mind before realising that the full
date was required anyway and collecting it this way was just lack of
knowledge (or laziness) on the part of the previous developer. However, Kiwis
always think "day/month/year" so selecting the month first probably wouldn't
go over very well. Better to just have one field and validate the value using
IsDate, format it using Format and then parse it on insertion into the
document. I'd rather that the code did more work and the user less since
that's the whole point of automation... ;-)

(And why is it that so many of my posts lately seem to have something to do
with dates and times? Phase of the moon? Colour of my socks? Numerology?)
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


macropod said:
Hi Gordon,

FWIW, if you forced the user to choose a year & month before the day, you could limit the day choices via a dropdown or spinner.

--
Cheers
macropod
[MVP - Microsoft Word]


Gordon Bentley-Mix said:
Hmm... not quite what I had in mind, but thanks anyway.

A couple of days later and my mind is not so mushy; however, I still can't
see a solution. It just seems a bit clunky to do it the way I am, but if it
works and it's all I've got...

At least this got me thinking about ways to improve things around where I'm
doing this comparison. I'm trying to make sure that the user enters a valid
day of the month. The code (which I inherited) just looks to see if the value
is between 1 and 31 without regard to the month. This got me thinking about
ways to vary the range of acceptable values according to the month selected,
and I thought I had a solution - a variable for the uppermost acceptable
value, a Case statement to set it and a function to take in the value and do
the validation accordingly.

HOWEVER...

I'm now questioning the reasoning behind entering the month and day
separately in the first place, as the full date is required anyway. I suspect
the UserForm was designed this way because the previous developer wanted to
be able to insert the various parts of the date into the document separately
(e.g. "the 10th day of September, 2006") and didn't know how to parse the
date. I'm MUCH smarter than that! <g> I'll just use IsDate to validate the
value and then pick it apart afterwards.

So not a wasted effort since it did get me to re-examine the business rule
behind the functionality.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


macropod said:
Hi Gordon,

I suppose you could use:
If Abs(MyNumber -50.5) > 49.5 Then MsgBox "Don't be a dork!"

--
Cheers
macropod
[MVP - Microsoft Word]


"Gordon Bentley-Mix" <gordon(dot)bentleymix(at)gmail(dot)com> wrote in message
I'm sure there's an easy answer to this, but I'm having a senior moment. Is
there a better way to determine if a number is within a range of acceptable
values other than using something like this?

If myNumber < 1 Or myNumber > 100 Then
MsgBox "Don't be a dork!"
End If

Dunno why but I have this feeling that there is and I'm just missing it.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top