using between and negative numbers

tubar

Registered User.
Local time
Today, 16:25
Joined
Jul 13, 2006
Messages
190
Code:
If Me.Text250 = BETWEEN \ -15 And 15 Then
Me.Label253.Visible = False
Else
Me.Label253.Visible = True

End If
Even when text250 =8 label253 is visible.
 
To my knowledge the BETWEEN Operator is only available within SQL Statements, i.e. in a Query. To do this in VBA code you'd need something like

Code:
If Me.Text250 >= -15 And Me.Text250 <= 15 Then
 Me.Label253.Visible = False
Else
 Me.Label253.Visible = True
End If
Linq ;0)>
 
Code:
If Me.Text250 >= -15 And Me.Text250 <= 15 Then
Me.Label253.Visible = False
Else
Me.Label253.Visible = True
End If

A more compact alternative would be:

Code:
Me.Label253.Visible = (Abs(Me.Text250) > 15)
 
In the days of 20mb hard drives, when memory was at a premium, and we had contests to see who could write the most compact code, I'd agree with that, but in today's world, with multi-terabyte hard drives, I just lean towards code that is more opaque! Especially since the person who has to modify the code is apt to be someone other than the original developer! But as with such things as haggis and sushi and okra, it's a matter of personal taste! :D

Linq ;0)>
 
I'd agree with that, but in today's world, with multi-terabyte hard drives, I just lean towards code that is more opaque! Especially since the person who has to modify the code is apt to be someone other than the original developer!

For some reason some developers have an aversion to setting the value of a property to the result of an expression that returns a boolean.

I really don't understand why anyone would prefer a verbose clump of code over a single line whose meaning is quite obvious.
 
one further issue is datatyping.

having a control/field called TEXT250 - and then testing numeric values raises concerns - as if the control is really a text value, and holds something like "Smith", or even a null - what would you expect the result of your test to be?
 
For some reason some developers have an aversion to setting the value of a property to the result of an expression that returns a boolean.

I really don't understand why anyone would prefer a verbose clump of code over a single line whose meaning is quite obvious.

Nothing is obvious to those who do not know.

I guess that years of maintaining ever changing programs due to company needs makes me prefer simple to change code, especially as its usually wanted yesterday, the next requirement may be between -15 and + 20 so I guess I go with linq

Brian
 
Nothing is obvious to those who do not know.
Sure, any piece of code or a function can be obscure to someone who has not seen it before. However if that was a valid criteria for avoidance then we couldn't write any code because someone might not have seen it before.

Abs() is a standard VBA function so I don't see why it should be singled out.

I guess that years of maintaining ever changing programs due to company needs makes me prefer simple to change code, especially as its usually wanted yesterday, the next requirement may be between -15 and + 20 so I guess I go with linq

For your alternative range requirement:
Code:
Me.Label253.Visible = (Me.Text250 > 20 Or Me.Text250 < -15)

However the actual objection I usually encounter to the coding style is to the use of an expression that returns a Boolean value directly letting the value of a Boolean property rather than explicitly letting it to True or False.

That objection is entirely irrational.
 
I was not objecting to abs but to obvious, yes it can easily be understood even if abs has to be looked up by one who has not come across it, but it is not necessarily obvious.
And yes letting the Boolean value can also be puzzling to a newbie, I've had to explain about that in the standard age calculation before today.

Brian
 
Last edited:

Users who are viewing this thread

Back
Top Bottom