MxFromString invalid format. Unsupported character

Hello

I hope I am not doing something wrong here. Please consider the following code:

m=Matrix(1,1,null);
m[0][0] = SelectedValue(DateTime());
printf(“date = “+DateTimeToStr(m[0][0])+”\n”);
s=MxToString(m);
printf(“s = “+s+”\n”);
m2 = MxFromString(s);

The last line gives error:

MxFromString invalid format. Unsupported character

I think it is getting confused exporting and then importing back the datetime() value. If instread of datetime() I use barindex(), then there is no message:

m=Matrix(1,1,null);
m[0][0] = SelectedValue(barindex());
printf(“barindex = “+numtostr(m[0][0], 1.0)+”\n”);
s=MxToString(m);
printf(“s = “+s+”\n”);
m2 = MxFromString(s);

I am using AB ver 6.25.0. 64bit.

Moderator comment: USE CODE TAGS !!! If you don’t use code tags, the formula gets corrupted

hello @bobptz

with the datenum() seems to be ok

DT = datenum();
m=Matrix(1,1,null);
m[0][0] = SelectedValue(dt);
printf("date = "+DateTimeToStr(m[0][0])+"\n");
s=MxToString(m);
printf("s = "+s+"\n");
m2 = MxFromString(s);

The reason is quite simple, explained many times. DateTime is NOT A NUMBER but you are treating it this way. See http://www.amibroker.com/f?datetime

Hi Tomasz

You mean that DateTime values are not suitable for matrix elements?

No. Again users instead of reading EXACTLY what I wrote, invent their own “interpretation”.
I wrote “DateTime is not a number”. I did not write anything else. I did not write that it can not be stored in matrix cell. So please do not come with your own interpretations. Your problem is because you are trying to FORMAT DateTime to string as if was a number. But datetime is not a number.

1 Like

Hi Tomasz

Your problem is because you are trying to FORMAT DateTime to string as if was a number.

You mean this line?
m2 = MxFromString(s);

I don’t understand what I did wrong. Datetime values are suitable for matrix elements and I am using MxFromString to convert the matrix to string. The doc page https://www.amibroker.com/guide/afl/mxfromstring.html does not have any relevent warning.

Maybe some other knowledgebase article that I failed to read?

No, I mean MxToString(). DateTime is NOT a number and can’t be treated as number and that is what you are doing calling MxToString.

Ok, I did not know this. Now I understand.

I think it would be helpful if you made a note in the MxToString documentation. Even better if there was a runtime error/warning if somebody did this.