Page 1 of 1

Expand "if" command

Posted: Sat Dec 06, 2008 10:56 am
by graves
Hi
1. It would be very useful to have a command "between" (like SQL). At this momment I'm using this macro

Code: Select all

macro between(btwfld, btwfrm, btwto)
  btwfld >= btwfrm AND btwfld <= btwto
endmacro

...
if between(datafield, valuefrom, valueto) ...

But it would be much more readable this construct:

Code: Select all

if datafield between valuefrom and valueto ...
2. Also we need to check same datafield against a lot of values (chained by OR), like this:

Code: Select all

if datafield = value1 OR value2 OR value3 ... 
Instead, I can use this construct:

Code: Select all

select datafield
  case value1, value2, value3:,,,
  default: ...
endselect
But it's not the same thing

BOTH cases can be unified in the next (generic) construct:

Code: Select all

if datafield [>=<] value1 [AND,OR] [>=<] value2 ....

Re: Expand "if" command

Posted: Sat Dec 06, 2008 12:44 pm
by PB
graves wrote:But it would be much more readable this construct:

Code: Select all

if datafield between valuefrom and valueto ...
I don't understand? How is the above any different to just doing this:

Code: Select all

if value(datafield)=>valuefrom and value(datafield)<=valueto
:?:

Posted: Sat Dec 06, 2008 1:17 pm
by AND51
Why not doing this:

Code: Select all

value=59

Select value
   Case 1 To 10, 90 To 100
      Debug "between 1-10 or 90-100"
   Case 14, 24, 34, 44, 54, 64, 74, 84
      Debug "value ends with 4"
   Case 35 To 41, 43
      Debug "value between 35-41 or equal to 43"
   Default
      Debug "any other value"
EndSelect

Posted: Sat Dec 06, 2008 5:53 pm
by Mistrel
If you're using OR statements you should group each part of the expression in parenthesis:

Code: Select all

(btwfld >= btwfrm And btwfld <= btwto) Or (N=2 And R=1)
This is the proper way to make this kind of statement 'more readable'.

Re: Expand "if" command

Posted: Mon Dec 08, 2008 11:32 pm
by luis
[quote="graves"]Hi
1. It would be very useful to have a command "between" (like SQL). At this momment I'm using this macro

Code: Select all

macro between(btwfld, btwfrm, btwto)
  btwfld >= btwfrm AND btwfld <= btwto
endmacro

...
if between(datafield, valuefrom, valueto) ...


Hi, I believe it's really something you can already do in many ways without the need to add another keyword to the language.