Re: Boolean Range by Matt
Matt
Thu May 15 07:48:48 CDT 2008
The more I think about this, it must have been back in my C++ (or maybe
earlier) days that I used this syntax. Like I said, it very seldom comes up
for me.
Thanks for all the input,
Matt
"SurturZ" <surturz@newsgroup.nospam> wrote in message
news:C7BE0DB6-352A-4BC3-9504-91D68C13A85D@microsoft.com...
> I'm pretty sure that
>
> If 1 <= x <= 10 Then...
>
> Has never been valid Microsoft BASIC syntax. If it ever worked it would
> not
> have given the correct value because at best the (1 <= x) would return -1
> (True) which would always be less than 10, so any value greater or equal
> to 1
> would return True.
>
> SELECT CASE x
> CASE 1 TO 10
> CASE ELSE
> END SELECT
>
> would give you what you want, or you could use
> IF 1 <= X AND X <= 10 THEN...
>
>
>
> --
> David Streeter
> Synchrotech Software
> Sydney Australia
>
>
> "Cor Ligthert[MVP]" wrote:
>
>> Peter,
>>
>> > Amen! I hope that someday Option Strict will be the default and
>> > unavoidable. IMHO, code quality would improve measurably.
>>
>> I changed my mind a while ago about this. Somebody stated the point
>> bellow
>> and I agree.
>>
>> As Armin, You and I have seldom a problem with casting, can option strict
>> off be a good start point for somebody just starts learning programming,
>> programming is in my idea learning to use logic, not learning to know
>> from
>> head every name of a property or/and method that there can be.
>>
>> I know that my knowledge about teaching is most probably very low against
>> yours.
>> But I found it a good point.
>>
>> Cor
>>
>>
>> "PvdG42" <pvan@toadstool.edu> schreef in bericht
>> news:%23mv0qXTsIHA.552@TK2MSFTNGP06.phx.gbl...
>> >
>> >
>> > "Armin Zingler" <az.nospam@freenet.de> wrote in message
>> > news:#$6$HRSsIHA.3780@TK2MSFTNGP03.phx.gbl...
>> >> "Matt MacDonald" <mattsmac@hotmail.com> schrieb
>> >>> Hi everyone,
>> >>> Maybe I'm just discovering something late that everyone else knew
>> >>> already, but it caught me off guard. In the past I could do an
>> >>> expression like "If 1 <= x <= 10 Then ..." to see if x was in the
>> >>> numeric range 1-10. So x = 5 would evaluate to True, whereas x = 0
>> >>> would evaluate to False.
>> >>
>> >> Can't repro this in VB6. Expression returns True in both cases.
>> >>
>> >>> Well now it seems that no matter what x
>> >>> is, the statement evaluates to True.
>> >>
>> >> One more reason why Option Strict should be switched On. The syntax is
>> >> not valid in VB.Net because "1 <= x" is a Boolean which is not defined
>> >> in conjunction with "<= 10". A Boolean can not be compared to an
>> >> Integer
>> >> value using the "<=" operator.
>> >>
>> >> VB6 did implicit conversions - wanted or not, without giving a warning
>> >> or an error. Option Strict makes you think about what has to happen.
>> >>
>> >>
>> >> AZ
>> >
>> > Amen! I hope that someday Option Strict will be the default and
>> > unavoidable. IMHO, code quality would improve measurably.
>> >
>> >>
>>