convert variables types
kanika
Posts: 247
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.
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.
0
Answers
-
First you can use a temp variable
T (decimal)
Then you run this code.
A (text, 7)
B (code)
C (decimal)
EVALUATE(T,
;
A = FORMAT(T + C)0 -
look at EVALUATE function in C/side reference guide.0
-
Hi Kanika,
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,
Floris0 -
B = 0000002 (code)
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 + Decimal0 -
you're welcome

please set topic as solved.
regards,
Floris0 -
still does not work
it is giving the same error0 -
is T a decimal and not text?0
-
Sorry Kanika,
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.
Floris0 -
it already works!
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?0 -
what you could do is the following:
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 performance0 -
=D>
Now It works perfectly!!
thanks thanks! FlorisB
How can I set topic as solved??0 -
And yet another formatting option:
PADSTR('', 7-STRLEN(FORMAT(result)), '0')+FORMAT(result)
There's probably better versions of this around.0 -
For example
FORMAT(Result,7,'<Integer,7><Filler Character,0>');
(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).0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
