Convert text to integer

anakinanakin Member Posts: 27
Hi all,

I want assign a text value to an integer variable but it raises a conversion error.

What's the solution ?

anakin ](*,)

Comments

  • matttraxmatttrax Member Posts: 2,309
    You can't assign text to an integer. If you want to have a separate variable that stores the text version of that number you can do:
    text_variable := FORMAT(integer_variable)
    
  • anakinanakin Member Posts: 27
    matttrax wrote:
    You can't assign text to an integer. If you want to have a separate variable that stores the text version of that number you can do:
    text_variable := FORMAT(integer_variable)
    

    It's not possible convert text to integer ?

    My sample code:

    text_var := '2000';
    if text_var > 1000 then
    ....
    ...

    Exist a solution ?

    Thanks
  • kinekine Member Posts: 12,562
    No, there is no automatic type cast in NAV. You need to convert the variable into integer variable and compare this with the value or you need to compare it with text value (but you can have different result...)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • WaldoWaldo Member Posts: 3,412
    And you convert with the "EVALUATE"-statement.

    declare a variable as integer and write a line like:

    EVALUATE(myInt, myText);

    the expression errors out when it's not possible to comvert to integer...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • DenSterDenSter Member Posts: 8,305
    So you'd have something like this:
    text_var := '2000'; 
    EVALUATE(MyInteger,text_var);
    if MyInteger > 1000 then 
      //code goes here
    
Sign In or Register to comment.