Format Text

ReSpongebobReSpongebob Member Posts: 17
Hi,

I'm rather new to Navision.

I'm asked to import data with a Dataport. The data imported does not always have the same format, as different users enter their data (everyone on his/her own way).

For example:
<= 50000
<= 50.000
<=50000
<=50.000

I need all this input in the same format:
* A space between the <, >, = and the actual number
* thousand-seperator
* decimal seperator

Both the input and the result are of type: Text

Is there a way to automate this with a pre-defined function or do I need to write a routine that checks the input-string character by character and adjust it as specified?

Please give me some information so I know how to solve this problem.

Thanks in advance!

Comments

  • s.delikostovs.delikostov Member Posts: 32
    You can create function that returns separators for current user:
    GetSeparator(VAR "Thousands Separator" : Text[1];VAR "Decimal Separator" : Text[1];VAR "Date Separator" : Text[1];VAR "Time Separator" 
    //GetSeparator
    tx1 := FORMAT(010203D);
    p1 := STRPOS(tx1,'01');
    p2 := STRPOS(tx1,'02');
    p3 := STRPOS(tx1,'03');
    "Date Separator" := '';
    IF (p1<p2) AND (p2<p3) THEN
      "Date Separator" := COPYSTR(tx1,p1+2,1)
    ELSE
      IF (p2<p1) AND (p1<p3) THEN
        "Date Separator" := COPYSTR(tx1,p2+2,1)
      ELSE
        "Date Separator" := COPYSTR(tx1,p3+2,1);
    
    tx1 := FORMAT(151617T);
    p1 := STRPOS(tx1,'15'); // returns 0 at US 3:xx PM!
    p2 := STRPOS(tx1,'16');
    p3 := STRPOS(tx1,'17');
    "Time Separator" := '';
    "Time Separator" := COPYSTR(tx1,p2-1,1);
    
    tx1 := FORMAT(123456/100);
    p1 := STRPOS(tx1,'1');
    p2 := STRPOS(tx1,'2');
    p3 := STRPOS(tx1,'4');
    p4 := STRPOS(tx1,'5');
    "Thousands Separator" := '';
    "Decimal Separator" := '';
    IF p2-p1 > 1 THEN
      "Thousands Separator" := COPYSTR(tx1,p1+1,1);
    IF p4-p3 > 1 THEN
      "Decimal Separator" := COPYSTR(tx1,p3+1,1);
    

    In the beginning of the Dataport call this function:
    IUtils.GetSeparator(ThousSep,DecimSep,DateSep,TimeSep);
    

    For Import, you must import all Decimals in Text variables and after that you must evaluate original fields:
    EVALUATE("Unit Price",CONVERTSTR(UnitPrice,'.',DecimSep));
    
    Stamen Delikostov
    Navision Solution Developer
    Intelligent Systems Bulgaria
  • ReSpongebobReSpongebob Member Posts: 17
    Thank you for your very quick reply :D

    I think it's a usefull function that I am defenitly gonna use.

    However, I don't know in advance what the user is going to enter.
    For instance, the user needs to enter a value Less than 45000

    It's possible the user enters:
    <45000

    But it's also possible that he will enter
    < 45000 (or some other variant).


    In order to get it into our database correctly, I need to format it to the same result, no matter what variant the user chooses.

    The end-result I need to achieve must be:
    < 45.000

    My question now is:
    How can I check wheter the space is present or not, and how to I insert one if the user omited it.
    Same goes for the thousand-seperator. If the user didn't enter a thousand-seperator, I need to insert it myself.

    Is this possible?
  • s.delikostovs.delikostov Member Posts: 32
    For spaces, first you can delete all spaces, and after the symbols '<>=' insert one "space".

    for the number you can evaluate it into a decimal variable and use FORMAT function to put thousand and descimal separator that you want.
    For example:
    FORMAT(Number,0,'<Sign><Integer><Decimals,3><1000Character,.><Comma,.><Precision,2:2>')
    
    Stamen Delikostov
    Navision Solution Developer
    Intelligent Systems Bulgaria
  • ReSpongebobReSpongebob Member Posts: 17
    Thank you so much, Stamen!
    With your advice I managed to write the function I need.
    =D>

    Kind regards,
  • andy76andy76 Member Posts: 616
    I really don't understand how format function parameters work.

    I have, in a text file a decimal field with this format:

    127.53

    where 127 is integer part

    and

    53 is decimal part

    I want to insert it in a decimal variable and table field of Navision but it depends of regional settings.
    I don't want it depends by Regional Setting. How is it possible?

    I want alway 127.53 and not for example 127530.

    Thank you very much
  • s.delikostovs.delikostov Member Posts: 32
    You have to use FORMAT function only when you want to convert non-text variable to text variable.

    When importing a text file, you must use EVALUATE instead of FORMAT. But first of all, you must convert decimal separator from "." to your separator, depending Regional Settings. It's simple:
    //Find you decimal separator:
    Str := FORMAT(123/2);
    DecSep := COPYSTR(str,2,1);

    //Read column form the text file in a text variable (for example ValueText), and convert '.' with your decimal separator:
    IF decsep <> '.' THEN
    ValueText := CONVERTSTR(ValueText,'.',DecSep);

    //Convert the text variable to your decimal field:
    EVALUATE("Decimal Field",ValueText);
    Stamen Delikostov
    Navision Solution Developer
    Intelligent Systems Bulgaria
  • andy76andy76 Member Posts: 616
    Thank you very much.
    It seems correct but for having the decimal separator in the example the right code is:

    DecSep := COPYSTR(str,3,1);

    Have a nice day.
  • AsallaiAsallai Member Posts: 141
    Hi Everyone.

    Anyone is meet with this error message?
    FORMAT is not a function??? ](*,)

    I do not know where shoud be the problem.
    I have tried in an individually codeunit Format and there is working... could I mistake something??
    This source is standard code of Item table, Costing Method OnValidate trigger.

    Anyone have an idea what is this?
    Thank you!
    A

    Okay, sorry, it was solved. recompile all objects! there was a new variable in a local function with the same name. Im .... :oops:
  • s.delikostovs.delikostov Member Posts: 32
    Probably you have a field with name Format.
    Is not good idea to use system words for naming fields, functions,...
    Stamen Delikostov
    Navision Solution Developer
    Intelligent Systems Bulgaria
Sign In or Register to comment.