You are not logged in.

1

Thursday, February 19th 2015, 2:42pm

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.

Source code

1
2
3
4
5
6
7
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

Umalo

Professional

Posts: 1,047

Location: Osijek, Croatia, EU

  • Send private message

2

Thursday, February 19th 2015, 8:54pm

I would say that forcing result (dstvar) of the subtxt to an numeric already existing variable is destroying it from memory. Simply don't do that. Use new variable to store subtxt result.

3

Friday, February 20th 2015, 10:24am

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