Hi!! I have 3 variables.
A (text, 7)
B (code)
C (decimal)
I need to do
A = B + C
but I don't know to convert types
Please, with function I need?
Thanks.
According to the message, I guess you're trying to add a text value to a decimal. The other way around should not give errors.
Please check that the value you wish to add is in the correct format.
(Why use format for conversion to standard format only? Format has parameters.
This version cuts off the fractional part. You probably should deal with a potential fractional part with any formating option given here (or use (big)integer in the first place).
Answers
T (decimal)
Then you run this code.
A (text, 7)
B (code)
C (decimal)
EVALUATE(T, ;
A = FORMAT(T + C)
can you tell us what you are trying to do? Does var b contain a number or a number with text?
Do ytou what to sum the var b and c?
I'll add to code samples, perhaps that helps.
1. Adding a number to a text:
b:='PINV';
c := 1.2;
a := b + format(c);
if you place this code in a codeunit and you add a message like this:
message(a);
the result wel be: PINV1.2
2. Sum the number values:
b := '5'
c := 1.2;
EVALUATE(d,b); //d is a var of the type decimal
a := FORMAT(d + c);
message(a) will result in 6.2
Hope this helps,
Floris
C = 2 (decimal)
I need to get 0000004 in A (text,7) for OutFile.WRITE(A)
THANK YOU VERY MUCH!!
stiasta, your code generates this error: Type conversion is not possible because 1 of the operators contains an invalid type. Text + Decimal
please set topic as solved.
regards,
Floris
it is giving the same error
I assumed your issue was solved.
According to the message, I guess you're trying to add a text value to a decimal. The other way around should not give errors.
Please check that the value you wish to add is in the correct format.
Floris
The problem was that B was in a Report DataItem and C in another.
but the result is '4' and I need '0000004'
I tried with padstr(string,7,0) but the result is '4000000' not '0000004'
pleaseeeeeeeee, How do I do?
IF STRLEN(a) <7 THEN
REPEAT
a:= '0' + a;
UNTIL STRLEN(a) = 7;
don't know if there is a better solution.....
---- EDIT ----
What also works is:
IF STRLEN(a) <7 THEN BEGIN
textvar := PADSTR(textvar, 7-STRLEN(a), '0');
a:= textvar + a;
END;
I suppose that's better for you performance
Now It works perfectly!!
thanks thanks! FlorisB
How can I set topic as solved??
PADSTR('', 7-STRLEN(FORMAT(result)), '0')+FORMAT(result)
There's probably better versions of this around.
This version cuts off the fractional part. You probably should deal with a potential fractional part with any formating option given here (or use (big)integer in the first place).