(DEV) What's wrong with the type conversion?

redhotmustangredhotmustang Member Posts: 91
Hi,

Please explain me.
I have an integer variable that receives the result of the getfilter function.
var := table.GETFILTER(year);

This year field is of the same data type of the var variable: integer.

But the system says "type conversion is not possible, integer := text". But the year field is an integer.

Later on, I need to add 1 to that value: year + 1. And this error will appear again. I read the evaluate function but I did not understand it.

How can I solve this?

Thanks in advance.
Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)

Answers

  • valkatamakevalkatamake Member Posts: 38
    i think it's
    var := table."year";
    
  • redhotmustangredhotmustang Member Posts: 91
    No, that does not work.
    Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
  • krikikriki Member, Moderator Posts: 9,110
    The GETFILTER ALWAYS returns a string, so you have to do this:
    EVALUATE(var,table.GETFILTER(year));
    

    Of course this means that the filter on year must filter ONLY 1 VALUE otherwise you will have an error anyway.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • redhotmustangredhotmustang Member Posts: 91
    The filter on year must return 2006, but lots of records for that year. So that didn't work.

    But I understood how the evaluate function works and solved the problem.
    VarYear := table.GETFILTER(year);
    EVALUATE(MyVar,VarYear);
    

    It works like this:
    The result of the getfilter function is contained in the code data type variable "VarYear", although the "year" field is an integer.

    "MyVar" is an integer data type variable.

    Then, the evaluate function places the value of the "VarYear" variable in the "MyVar" variable, transforming the value of the code data type variable "VarYear" into an integer value in the "MyVar" variable.

    Making it possible to add 1 to "MyVar" value.

    I think this is it.
    Thank you.
    Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
  • XypherXypher Member Posts: 297
    You should always have an error trap on evaluate imo...
    IF NOT EVALUATE(MyVar,table.GETFILTER(year)) THEN
      ERROR('your error here');
    

    (Like kriki was saying, the filter on year could have a range: '01/01/08..02/02/08' and would throw an error on your evaluate)
  • redhotmustangredhotmustang Member Posts: 91
    Xypher wrote:
    (Like kriki was saying, the filter on year could have a range: '01/01/08..02/02/08' and would throw an error on your evaluate)

    Yes, I got that after posting my reply, that is not lots of records, but more than one value for that filter.

    That error trap is it still necessary if the one data item's ReqFilterFields is that year field? I mean if we don't filled it in the report won't run, or it won't do anything. I'm just correcting this report, and I could change it to include this error trap, but I ended up using a variable being evaluated in another situation.
    Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
  • DenSterDenSter Member Posts: 8,305
    Somewhere the filter gets set and I'd try and catch that value there instead of trying to retrieve it from the filter. There are two other filterfunctions you can try to use for individual values, which are the GETRANGEMIN and GETRANGEMAX functions, look it up in the C/SIDE reference guide for more details. You also don't have to put the return value into a separate variable, you can go straight into the integer:
    IF EVALUATE(SomeIntegerVariable,Table.GETRANGEMIN(Field)) THEN
      MESSAGE('evaluated the lowest value in the filter')
    ELSE
      MESSAGE('could not evaluate the value');
    
    This is assuming that the field holds an integer type value. If it holds a date value, you'd have to use one of the date functions to get the integer representation of any of the elements of the date.
  • redhotmustangredhotmustang Member Posts: 91
    Thanks that's really helful. I'll read more about it in C/SIDE reference guide.
    Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
Sign In or Register to comment.