Coverting numbers to text

I am a relativley new developer and I need to do this text conversion. I have seen that this is possible in report 1401 on Navision Financials v2.00. I tried to copy the functions and get this to work to print a two digit string, but to no sucess. The error seems to point to the no. of dimension on the array but I think that I may need to recode the whole thing. Can anyone point me in the right direction to showing how this works as all I need to do is convert upto a three digit string into text.

The two functions to use, getting from variables to text an vice versa are: FORMAT EVALUATE Copy from Financials Help: FORMAT: String := FORMAT(Value [, Length] [, FormatNumber / FormatString]) String Data type: text or code This string contains the formatted output. Value Data type: any This is a C/AL variable (expression) of any simple data type, such as option, integer, decimal, char, text, code, date, time, boolean, or binary. If, when the system formats Value, the result is a value larger than the maximum length MAXSTRLEN of String, a run-time error occurs. Length Data type: integer Use this optional argument to determine the length of String. These rules apply: If Length… It means… Equals zero (0) The system will return the entire value (default) Is greater than zero (0) String will be exactly Length characters. If Value is less than Length characters, the system inserts either leading or trailing spaces, depending on the format you select. If Value is an integer which exceeds Length digits, the system places Length asterisks in String.If Value is not an integer and it exceeds Length characters, the system truncates String accordingly. Is less than zero (0) String will have the maximum length of Length characters.If Value is less than Length characters, the length of String will equal the length of Value.If Value is an integer which exceeds Length digits, the system places Length asterisks in String.If Value is not an integer and it exceeds Length characters, the system truncates String accordingly. FormatNumber Data type: integer Use this optional argument to determine the format you want the system to use. Here is a list of the basic options. The example below explains all available formats: To use this format… Select… Standard Display Format (the default for all data types) 0 Standard Display Format 2 (edit) 1 C/AL Code Constant Format 2 FormatString Date type: string A literal string that defines a format as in the Format property. Note: You can only use one of FormatNumber and FormatString at a time. Example This example shows how to use the FORMAT function. MESSAGE(‘The formatted value: >%1<’, FORMAT(-123456.78, 15, 3)); The message window shows: The formatted value: > 123,456.78 To use a string to build a format, use the function like this: MESSAGE(‘Today is %1’, FORMAT(TODAY,0,’ .’); which could give this message: Today is April 15. Comments The description of the Format property describes the various predefined formats in detail, and also how to create customized formats. EVALUATE: Use this function to evaluate a string representation of a value into its normal representation. The system assigns the result to a variable. [Ok :=] EVALUATE(Variable, String) Ok Data type: boolean A return code which reflects whether an error occurred during the evaluation of the string. If Ok is… It means… TRUE No errors occurred during the evaluation of the string. The system assigned the value to Variable. FALSE Errors occurred during the evaluation of the string. The system did not modify the original value of Variable. If you omit this optional return value and an error occurs during the evaluation of the string, a run-time error occurs. If you include it, the system assumes you will handle any errors. Variable Data type: boolean, integer, option, date, time, text or code Any type of variable. The value of the string is assigned to the variable. String Data type: text or code A string containing a value of any simple C/AL data type. Example This example shows how the EVALUATE function works when called with three different types of variables. Value := ‘010196’; Ok1 := EVALUATE(VarInteger, Value); Ok2 := EVALUATE(VarDate, Value); Ok3 := EVALUATE(VarYesNo, Value); MESSAGE(‘VarInteger = #1######, and the return code is: %2’ + ‘VarDate = #3######, and the return code is: %4’+ ‘VarYesNo = #5######, and the return code is: %6’, VarInteger, Ok1, VarDate, Ok2, VarYesNo, Ok3) The message window shows: VarInteger = 10196 , and the return code is: Yes VarDate = 01/01/96, and the return code is: Yes VarYesNo = No , and the return code is: No This example shows that while the system can interpret Value (‘010196’) as both an integer and a date expression, it cannot interpret it as a boolean expression. This causes an error, shown in the return code Ok3 (=FALSE). Joerg R Feldhofen KUMATRONIK Business Solutions Houston, TX

This does not quite cover what I had in mind. Here is what I need to do: Take an integer - i.e. 69,4 Convert this to text - Six Nine, Four or Convert to text - Sixty Nine, Four. Many Thanks

The report 1401 (Check) method is a fairly straight forward way of determining the size of the numeric value (from billions down to units) and assign a word for each digit it finds. As you say to be rather new to developing, my guess here is that you did copy the functions, but didn’t dimension the arrays used. To do this, call up the variables overview (either the local or the global), put your cursor on the variable, then call up its properties. There you set the array dimensions. Take the 1401 report as reference. The variable OnesText, for example, has Dimensions set to 20. John

I have re-thought the way in which I am approaching this. As the variable I have is an integer, and the length can be upto three digits, maybe it would be easier to split down the variable into three (possibily) seperate fields and then return a value from that ?

First of all you should have a function “Replace” which allows you to replace one substring with another substring: Function Replace (st,OldText,NewText : Text250) : stNew : Text250 // Take care! If oldText is part of NewText you’ll get a // “Loop-and-never-come-back”! // thus IF STRPOS(NewText,OldText) > 0 THEN BEGIN st := Replace(st,OldText,’$$$’); StNew := Replace(st,’$$$’,NewText); // hoping that ‘$$$’ is not part of the string! END ELSE BEGIN LenOld := STRLEN(OldText); IF OldText = NewText THEN EXIT; i := STRPOS(st, OldText); WHILE i > 0 DO BEGIN st := DELSTR(st,i,LenOld); st := INSSTR(st,NewText,i); i := STRPOS(st, OldText); END; stNew := st; END; — You can now call st := Replace (‘012341’,‘1’,'One '); and get as result st = ‘0One 234One’); The rest is easy: st := ‘4711,35’; DecStr[1] := 'Zero '; DecStr[2] := 'One '; DecStr[3] := 'Two '; DecStr[4] := 'Three '; DecStr[5] := 'Four '; DecStr[6] := 'Five '; DecStr[7] := 'Six '; DecStr[8] := 'Seven '; DecStr[9] := 'Eight '; DecStr[10] := 'Nine '; FOR i := 0 TO 9 DO st := Replace(st,FORMAT(i),DecStr[i+1]); MESSAGE(st); — Marcus Marcus Fabian phone: +41 79 4397872 m.fabian@thenet.ch