Simple Question - IN Statement

AngeloAngelo Member Posts: 180
Hi master,

Is it possible to use "IN" statement for choose range of value?
for example,

If GLAccount."No." IN ('50000..51000') then ...

I've already tried but cant. Maybe there is something missing in my code. Please advice....

Thanks

Comments

  • DenSterDenSter Member Posts: 8,307
    Nope, ranges don't work with IN statements, but you already knew that :mrgreen:
  • AngeloAngelo Member Posts: 180
    is it possible to use IN if the option value is very big without key in one by one in bracket(hardcode)?
    I dont want to use
  • GRIZZLYGRIZZLY Member Posts: 127
    Here is some trick:
    you can use filter on GLAccount like that:
    GLAccountRec.SETFILTER("No.",'%1..%2&%3',50000,51000,GLAccountNo);
    IF GLAccountRec.FINDFIRST THEN ... ;
    Sincerely yours, GRIZZLY
    Follow my blog at http://x-dynamics.blogspot.com
  • idiotidiot Member Posts: 651
    Use > and <
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
  • Torben_R.Torben_R. Member Posts: 99
    Yes it's possible to use ranges and the IN statement.
    if GlAccount."No." IN ["50000".."51000"] then
    
  • matttraxmatttrax Member Posts: 2,309
    Torben R. wrote:
    Yes it's possible to use ranges and the IN statement.

    Tested in a 2009 classic client with strings and integers. Worked fine. I was surprised. I didn't recall this being possible.
  • AngeloAngelo Member Posts: 180
    if GlAccount."No." IN ["50000".."51000"] then
    only in Navision 2009? I use Navision 5 but cant.
  • matttraxmatttrax Member Posts: 2,309
    I notice that the example uses double quotes instead of single quotes. Could that be the problem? I don't know when they syntax became available.
  • jversusjjversusj Member Posts: 489
    from the Dev I manual...
    Relational Expressions for Set Inclusion
    The relational operator IN is used to determine inclusion. It determines if the first
    term is in a specific set. Therefore, it requires a list of values, a set, to compare
    the term to. This list is part of the expression and is called a set constant.
    Set Constant
    There are no variables of type set, but there are constants of type set. A set
    constant consists of an open square bracket ([) followed by a list of allowed
    values separated by commas, followed by a close square bracket (]). For
    example, a set of all the even numbers from one to ten looks like this:
    [2,4,6,8,10]
    Besides individual values, a member of a set can also be a range of values. A set
    of all the numbers from one to twenty not evenly divisible by ten looks like this:
    [1..9,11..19]
    In addition, an individual value or a value used as part of a range can actually be
    an expression. A list of numbers from 10 to 20, but not including the variable n
    (as long as n was from 10 to 20), looks like this:
    [10..n-1,n+1..20]
    This does not help with syntax much, but suggests ranges are acceptable. This is from the manual that was published for V5.
    kind of fell into this...
  • AngeloAngelo Member Posts: 180
    Ranges are acceptable if the value type is Integer but are not acceptable if the value type is Code like :
    if GlAccount."No." IN ["50000".."51000"] then
    double quote is also not acceptable :)

    @matttrax
    you said that range can be done in classic client 2009 and worked fine. maybe you mean that range can be done if value type is integer,isnt it? :-k
  • matttraxmatttrax Member Posts: 2,309
    No, the following code compiles and runs just fine in a NAV 2009 SP1 Classic Client.

    IF 'A' IN THEN
    MESSAGE('Found A')
    ELSE
    MESSAGE('Did not find A');
  • idiotidiot Member Posts: 651
    matttrax wrote:
    No, the following code compiles and runs just fine in a NAV 2009 SP1 Classic Client.

    IF 'A' IN THEN
    MESSAGE('Found A')
    ELSE
    MESSAGE('Did not find A');

    This ran even in 4.0 so it was around for a while
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
  • ZephyrZephyr Member Posts: 110
    You can use "IF temp IN [1..9] then" in NAV 4.0 SP3

    Just check it.
    Zephyr
  • ZephyrZephyr Member Posts: 110
    You can use "IF temp IN [1..9] then" in NAV 4.0 SP3 also.

    Just check it.
    Zephyr
  • matttraxmatttrax Member Posts: 2,309
    It's always good to learn something new. Four years of NAV development and I didn't realize this was an option. :oops: So much for those giant CASE statements.
  • GianfrancoGianfranco Member Posts: 8
    Anybody succeeded in using a variable with a IN statement?
    Sort of
    IF AnyRecord.Field IN [TextField] THEN ...
    where TextField should contain something 'VALUE1,VALUE2,VALUE3'.

    Thanks
Sign In or Register to comment.