c3=LEFT(ALLTRIM(CHRTRAN(examcode,"0123456789","")),3)strips out all the numbers from c3, which means that your Rep2 function will always fail unless the input is "annual". Since you don't have any OTHERWISE in the function, it will return .F. for most values, which is the source for your "Data Type Mismatch".