subtxt() delivers NaN if the result variable contained a number

  • If subtxt() is used with a result variable that stores the result of a preceeding indexoftxt() or a mathematical operation, then the result is NaN instead of the extracted string.

    If the result variable has never been used or stores a text, everything is OK.

    Code
    set(var, "A string! A string.");
    indexoftxt(num_result, get(var), "!" );
    subtxt(num_result, var, 2, 7);
    set(str_result, "abc");
    subtxt(str_result, var, 2, 7);
       trace('result in num_result: ', num_result);
       trace('result in str_result: ', str_result);

    Output:
    INFO: result in num_result: NaN
    INFO: result in str_result: string!

    It looks like 'num_result' has an attribute "I'm a numerical value" which is not changed in subtxt().

    Best regards,
    Wolfgang

  • Hi,

    the reason is when the destination variable already exists, but with a different type (e.g. Number instead of String), then that type will be kept and the to be assigned value converted to that type. And assigning a text to a number will fail and result in a 'NaN' (Not a Number).

    This will be fixed in the next release - then the destination variable will be fully overwritten (including the type) when using the subtxt, indexoftxt or txtreplace actions.

    Best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!