DATA TYPE CONVERSION

KimKim Member Posts: 85
Hi, Am having some trouble converting data types. am working on a payroll
where am supposed to use formulas. for example: strformula:='((([BPAY]/20)/8)*1.5)*[P003]';
Am holding the formula first on a Text Variable because the value of BPAY and P003 can vary from employee to
another.
Am stuck in trying to convert the text variable strFormula to Decimal so i can insert the formula to a decimal field.
any one got an idea how i can do this.

:?:

Comments

  • rhpntrhpnt Member Posts: 688
    What's the error message?
  • KimKim Member Posts: 85
    rhpnt wrote:
    What's the error message?

    Type conversion is not possible because one of the operators contain an invalid type
  • lubostlubost Member Posts: 623
    Hi,

    easier way is to change your code
    strformula:='((([BPAY]/20)/8)*1.5)*[P003]';
    to
    strformula:='(((%1/20)/8)*1.5)*%2';

    and then use
    formula := STRSUBSTNO(strformula, BPAY, P003);
    and then use EVALUATE function to obtain final result.
  • rhpntrhpnt Member Posts: 688
    Kim wrote:
    rhpnt wrote:
    What's the error message?

    Type conversion is not possible because one of the operators contain an invalid type

    Did you check the content of strformula via debugger or a message?
  • KimKim Member Posts: 85
    lubost wrote:
    Hi,

    easier way is to change your code
    strformula:='((([BPAY]/20)/8)*1.5)*[P003]';
    to
    strformula:='(((%1/20)/8)*1.5)*%2';

    and then use
    formula := STRSUBSTNO(strformula, BPAY, P003);
    and then use EVALUATE function to obtain final result.


    thanks
    let me try this
  • KimKim Member Posts: 85
    lubost wrote:
    Hi,

    easier way is to change your code
    strformula:='((([BPAY]/20)/8)*1.5)*[P003]';
    to
    strformula:='(((%1/20)/8)*1.5)*%2';

    and then use
    formula := STRSUBSTNO(strformula, BPAY, P003);
    and then use EVALUATE function to obtain final result.

    if i try to use the EVALUATE function this way:
    EVALUATE(finalformula,strformula);
    finalformula is a decimal variable
    am getting
    an error [You cannot insert "(((100/20)/8)*1.5)*110"] in decimal]
    ](*,)
  • KimKim Member Posts: 85
    May be someone who has customized or developed payroll system can assist.
    Some values in payroll are as a result of calculation formulas provided for by the Revenue authorities
    or any other body for example. VALUE:='(((BASICPAY/20)/8)*1.5)*NOOFHRS'
    for my case i intent to handle them from setup since from previous experience they have proved to be
    enough problems if done within the code.
    Has anyone handled such kind of formulas and how did u go about it???
  • rhpntrhpnt Member Posts: 688
    Kim wrote:
    lubost wrote:
    Hi,

    easier way is to change your code
    strformula:='((([BPAY]/20)/8)*1.5)*[P003]';
    to
    strformula:='(((%1/20)/8)*1.5)*%2';

    and then use
    formula := STRSUBSTNO(strformula, BPAY, P003);
    and then use EVALUATE function to obtain final result.

    if i try to use the EVALUATE function this way:
    EVALUATE(finalformula,strformula);
    finalformula is a decimal variable
    am getting
    an error [You cannot insert "(((100/20)/8)*1.5)*110"] in decimal]
    ](*,)

    The error is clear and your posts show that you may be lacking on basic knowledge of datatypes. You simply cannot put a string into a decimal field, period!
  • rhpntrhpnt Member Posts: 688
    Why are you trying to put the formula string into the decimal field? Wouldn't it be logical to put the result of the formula into it?
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    OK so basically you are trying to develop a solution where calculations can be defined by users via formulas or expression. What you need is basically developing an expression evaluator - take a look at the EvaluateExpression function in Codeunit 8 and create something similar.
  • KimKim Member Posts: 85
    OK so basically you are trying to develop a solution where calculations can be defined by users via formulas or expression. What you need is basically developing an expression evaluator - take a look at the EvaluateExpression function in Codeunit 8 and create something similar.

    Thanks had not thought of that functionality in codeunit 8

    :whistle:
Sign In or Register to comment.