How to split a record and format to string?

RosOmarRosOmar Member Posts: 7
Lets say we have a Code record with 3 digits. Based on first digit we would want to format to string?

Example:
001 = Lion
101 = Tiger
201 = Moth

Would appreciate any help.

Best Answer

  • aniishaniish Member Posts: 27
    Answer ✓
    Hi,

    You can try below code
    If ItemVarient.findset then 
      repeat
        String := COPYSTR(ItemVarient.Code, 1, 1);
        CASE String OF 
          '1' : BEGIN
            Newtab.init;
            Newtab.code := '1';
            Newtab.value := 'Black';
            IF Newtab.inset THEN;
          END;
        END; 
      until ItemVarient.next = 0;
    

Answers

  • JustJoshJustJosh Member Posts: 4
    Hi RosOmar,

    I take it the records do not have the values you want to output stored on a field on the record?

    I'm not really sure why you would want to do this but I don't know the context. You code do something like this, where Code var is just representing the record (I assume it's PK) -> get the 1st char -> hardcode the values in a case.

    I don't really like this solution but a part of it might help. I would prefer to have the values on the record or linked in another table etc.
    Code := '100';
    String := COPYSTR(Code, 1, 1);
    CASE String OF 
      '1' : 
        MESSAGE('Example');
    

    Josh
  • RosOmarRosOmar Member Posts: 7
    Josh,

    Thanks for reply.

    The Code var is indeed a record and the values too need to get linked to a table.

    Basically we have a record from Item Variant table. Then based on 1st number, the record need to be converted/formated to, lets say Colour (1 = black, 2 = white etc), then this colour will be inserted to a different table.... So this new table will act as a translator.

    Would appreciate further advice.

    Thanks in advance.

  • aniishaniish Member Posts: 27
    Answer ✓
    Hi,

    You can try below code
    If ItemVarient.findset then 
      repeat
        String := COPYSTR(ItemVarient.Code, 1, 1);
        CASE String OF 
          '1' : BEGIN
            Newtab.init;
            Newtab.code := '1';
            Newtab.value := 'Black';
            IF Newtab.inset THEN;
          END;
        END; 
      until ItemVarient.next = 0;
    
  • RosOmarRosOmar Member Posts: 7
    Aniish thank you very much. This is it!!
Sign In or Register to comment.