Compare text type variable with code type variable

zpgmzpgm Member Posts: 6
Hi all,

I am having a hard time using STRPOS() to compare a CODE and a TEXT variable.

Here's what I have:

VAR:
myTxt TEXT(80)
myCode CODE(20)

myCode:= '329021277';
myTxt:= '329021277/5504';

using STRPOS(myTxt, myCode) always returs 0!!
I've already used the FORMAT function to cast one type to another but keeps on returning 0.

I will try to parse both variables char by char...but I would like to know the reason why this happens. :)

Thank you all.

Best regards.

Comments

  • KishormKishorm Member Posts: 921
    Strange as I would expect it to work too, however if it doesn't then you can simply assign the code variable to another text variable and then just use the 2 text vars in STRPOS
  • vaprogvaprog Member Posts: 1,141
    As expected, your code (as stated here) is working for me (NAV 2009 R2 / 6.00.30012).
    Re-examine what you really coded.
  • zpgmzpgm Member Posts: 6
    Thanks for your replies.

    The code I posted is working fine... I oversimplified my error and mislead you all (even myself :) ).

    I have a few customized fields in my "Job Ledger Entry" table and one of them is a Text(80).
    I have an automated process that imports data from a CSV file and saves it in a table (let's call it "Imported Lines"). Then all that imported data is validated and if it is ok is posted in the "Job Journal Line". Finally, using the "Job Jnl.-Post" codeunit post that data in the Job Ledger Entry.
    All those posted records have only one field that can be edited (in the Job Ledger Entry table) by the user and a few times its content is modified.

    In a process I designed I am comparing records in the Job Ledger Entry with records in the "Imported Lines":
    ImportLines.RESET;
    IF ImportLines.FIND('-') THEN
      REPEAT
    
         JobLedgEntry.RESET;
         JobLedgEntry.SETFILTER("Journal Batch Name"  , 'GTROUPAS|GTRESIDUOS');
         JobLedgEntry.SETRANGE("Job No.", ImportLines."Job No");
         JobLedgEntry.SETRANGE("Posting Date", ImportLines."Post Date");
         JobLedgEntry.SETRANGE("No.", ImportLines."Resource Code");
         IF JobLedgEntry.FIND('-') THEN
            REPEAT
                IF STRPOS(JobLedgEntry."Transport Num.", ImportLines."Transport Num.") > 0 THEN BEGIN
                    ...
                END;
            UNTIL JobLedgEntry.NEXT = 0;
      UNTIL ImportLines.NEXT = 0;
    

    The JobLedgEntry."Transport Num." is a Text(80) and the ImportLines."Transport Num." is a Code(20).

    I tried debugging with a message box displaying the return value of STRPOS and that message displays 0... The values I posted before (in the myTxt and myCode)are values that exist in both tables.
    I tried casting the value of the text variable to a code variable and use that one in the SRTPOS with no luck.

    Thanks once again.
Sign In or Register to comment.