Filter integer field with >

MarcosMarcos Member Posts: 55
Question,

Id writed a code that will filter contact feature type's from the contact feature type table.
But i want to skip lines, so i can put this data in columns of an other table.

CODE:
ContactFeatureTypeRec.RESET;
ContactFeatureTypeRec.SETRANGE("Feature Group",'Stabu paragraaf');
ContactFeatureTypeRec.SETRANGE(Code,Relatie);
ContactFeatureTypeRec.SETRANGE("Line No.",LineInt);
IF ContactFeatureTypeRec.FINDFIRST THEN BEGIN
REPEAT
STABU := ContactFeatureTypeRec.Feature;
LineInt := ContactFeatureTypeRec."Line No.";
UNTIL ContactFeatureTypeRec.NEXT = 0;
END;

What i want to do is filter > on the next line

CODE:
ContactFeatureTypeRec.RESET;
ContactFeatureTypeRec.SETRANGE("Feature Group",'Stabu paragraaf');
ContactFeatureTypeRec.SETRANGE(Code,Relatie);
ContactFeatureTypeRec.SETRANGE("Line No.",>LineInt);
IF ContactFeatureTypeRec.FINDFIRST THEN BEGIN
REPEAT
STABU1 := ContactFeatureTypeRec.Feature;
LineInt := ContactFeatureTypeRec."Line No.";
UNTIL ContactFeatureTypeRec.NEXT = 0;
END;


But i get an error on the > sign, does somebody has an solution here ?

Comments

  • HalMdyHalMdy Member Posts: 429
    Use SETFILTER instead ...

    ContactFeatureTypeRec.SETFILTER("Line No.",'>%1',LineInt);

    or use SETRANGE like :

    Record.SETRANGE(Field [,FromValue] [.ToValue])
  • MarcosMarcos Member Posts: 55
    thnx


    where stands the %1 for ??

    LineNo ??
  • MarcosMarcos Member Posts: 55
    Is doenst work for me, i get the error

    Type conversion is not possible because 1 of the operators contains a invalid type.
    Integer := Text
  • SavatageSavatage Member Posts: 7,142
    what type is LineInt declared as?
  • BgestelBgestel Member Posts: 136
    btw

    you should use

    findset in stead of findfirst when you are going to loop the records.

    oops off topic :mrgreen:
    **********************
    ** SI ** Bert Van Gestel **
    **********************
  • krikikriki Member, Moderator Posts: 9,110
    Bgestel wrote:
    btw

    you should use

    findset in stead of findfirst when you are going to loop the records.

    oops off topic :mrgreen:
    You're forgiven for this time :mrgreen:
    I have seen that error a lot of times.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • MarcosMarcos Member Posts: 55
    LineInt is declared as Integer
  • DenSterDenSter Member Posts: 8,305
    SETFILTER should automatically convert data types, but you can always do
    ContactFeatureTypeRec.SETFILTER("Line No.",'>%1',FORMAT(LineInt));
    
  • diptish.naskardiptish.naskar Member Posts: 360
    DenSter wrote:
    SETFILTER should automatically convert data types, but you can always do
    ContactFeatureTypeRec.SETFILTER("Line No.",'>%1',FORMAT(LineInt));
    

    Hi Daniel,

    There are actually 2 things to notice here

    1. The first code in the post

    ContactFeatureTypeRec.RESET;
    ContactFeatureTypeRec.SETRANGE("Feature Group",'Stabu paragraaf');
    ContactFeatureTypeRec.SETRANGE(Code,Relatie);
    ContactFeatureTypeRec.SETRANGE("Line No.",LineInt);
    IF ContactFeatureTypeRec.FINDFIRST THEN BEGIN


    Here also there is a setrange ContactFeatureTypeRec.SETRANGE("Line No.",LineInt); but according to Marcos post.....this never gives the error. :-k

    2. While just the next set contains ContactFeatureTypeRec.SETRANGE("Line No.",>LineInt); and this generates the error.

    Obviously the > sign causes the error, but when the setfilter is used along with this, it starts to give the type conversion error. FORMAT will definitely solve the error provided the "Line No" field is a code/text field.

    But the error should also come in the first set of code...Marcos, do check the datatypes of both the "Line No." and Lineint, if both the fields are integer and defined properly then it should not give the error.
    Diptish Naskar
    For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
  • WaldoWaldo Member Posts: 3,412
    Indeed, LineInt and field "Line No." should have the same data type.

    I have one side remark on your code ...
    Don't use FINDFIRST in front of a loop. Only use FINDFIRST if you only need the first record. Use FINDSET or FIND('-') instead... .

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • DenSterDenSter Member Posts: 8,305
    My point was that if the system screams at you because there is a data type conflict (integer > text), you can use the FORMAT command to convert the integer to text.
  • WaldoWaldo Member Posts: 3,412
    Also keep in mind the sortings.

    For text, the sorting is 1, 10, 2, 3, 30, 4, 5
    For integers, the sorting for these number is 1,2,3,4,5,10,30

    in this case (filtering < a value), I guess the only way to go is using all integers ... .

    But in any way ... Denster is right ... to resolve the error message, you can use the FORMAT to resolve the conversion error.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
Sign In or Register to comment.