Options

Fieldref Code field to Variant

fhoogfhoog Member Posts: 5
In the following code I open the ‘Vendor’ table (23) and read the first field ‘No.’ (Data Type ‘Code 20’).

Locals:
lVarValue Variant
lRrfTable RecordRef
lFrfField FieldRef


Code
lRrfTable.OPEN(23);
lRrfTable.FINDFIRST;
lFrfField := lRrfTable.FIELD(1);
lVarValue := lFrfField.VALUE;
MESSAGE('Result:%1',lVarValue);


Assume the value of the first field in the first record of table 23 is '10000' then the result of this function is 10000 with a square before it.

Does anyone have a solution to this?
I already tried lVarValue := FORMAT(lFrfField.VALUE), which works fine, but it is not preferable for other datatypes.

Comments

  • Options
    ara3nara3n Member Posts: 9,256
    I would suggest using case statement and handle each datatype differently

    lRrfTable.OPEN(23);
    lRrfTable.FINDFIRST;
    lFrfField := lRrfTable.FIELD(1);
    FieldType := format(lFrfField.TYPE);
    case FieldType of
      'Code': CodeValue :=  lFrfField.VALUE;
      'Integer':;
    end;
    
    MESSAGE('Result:%1',CodeValue);
    
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    fhoogfhoog Member Posts: 5
    Actually I want to write a function to read a value of a given table number and field number. This function would need to have too many parameters (e.g. for every possible data type a different one).

    Now I am going to try an other solution where code is always converted to text. Of course does code then always show up as text in the variant, but in my case that's no problem.

    IF FORMAT(lFrfField.TYPE) = 'Code'
    THEN vVarValue := FORMAT(lFrfField.VALUE)
    ELSE vVarValue := lFrfField.VALUE;


    I hope other data types don't have similar problems.
  • Options
    fhoogfhoog Member Posts: 5
    By the way, the problem of the added square only arises if the field (of data type Code) contains a value. If it's partially text no problem occurs.
  • Options
    ara3nara3n Member Posts: 9,256
    I don't know why it would add the extra character, which looks like carriage return
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    fhoogfhoog Member Posts: 5
    I read the value of the first character and it seems to be the length of the string.
  • Options
    ara3nara3n Member Posts: 9,256
    Interesting. :-k
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    krikikriki Member, Moderator Posts: 9,090
    fhoog wrote:
    I read the value of the first character and it seems to be the length of the string.
    Could be. In Navision, strings as stored with the length in the first character (Like Pascal) and not null-terminated (like C).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.