<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Strings arithmetic with a Variant in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/strings-arithmetic-with-a-variant/m-p/13550816#M55537</link>
    <description>&lt;P&gt;In all the examples you have given, you are using a binary operator with a Variant and a non-variant (int or double) value. If the Variant is on the right, then the variant is first cast to a number. in the case of the string variant, that will always be zero. If the Variant is on the left, the Variant checks to see if it is a number type. If it is, it casts itself to a number and does the operation. If not, the operator will return the value on the right.&lt;/P&gt;&lt;P&gt;If both values are Variants, then both must be string or number types. In the string case, you can only add. If you are not adding strings, or if the types mismatch, you will get a null value.&lt;/P&gt;&lt;P&gt;This behavior is by design. &lt;A rel="user" href="https://answers.flexsim.com/users/207/anthony.j.html" nodeid="207"&gt;@anthony.johnson&lt;/A&gt; may have some further insight. As a way to catch this issue sooner, try to do Variant math rather than Variant/non-Variant math. This will produce null values, rather than numbers, if there is a type mismatch.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Sep 2017 18:13:08 GMT</pubDate>
    <dc:creator>JordanLJohnson</dc:creator>
    <dc:date>2017-09-06T18:13:08Z</dc:date>
    <item>
      <title>Strings arithmetic with a Variant</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/strings-arithmetic-with-a-variant/m-p/13550815#M55536</link>
      <description>&lt;P&gt;
	&lt;A href="https://answers.flexsim.com/questions/ask.html#"&gt;@Patrick Zweekhorst&lt;/A&gt; found some interesting behavior when variants containing strings are involved in arithmetic. For example, consider the following:&lt;/P&gt;
&lt;PRE&gt;Variant str = "Hello world";
return [1 + str, str + 1, 60 * str, str * 60, str / 10, 10 / str];
// Gives [1, 1, 0, 60, 10, 1.#INF00]
&lt;/PRE&gt;&lt;P&gt;
	I cannot even figure out what is going on here: sometimes strings behave as the identity (0 for addition, 1 for multiplication) but not always and the operators no longer even seem commutative.&lt;/P&gt;&lt;P&gt;
	It would have made sense if this threw an exception, or even just gave 0.&lt;/P&gt;&lt;P&gt;
Of course, the solution is not to use strings and check the type first before you do. But in this case, where the variant was read from a table (&lt;CODE&gt;str = Table("GlobalTable")[1][1]&lt;/CODE&gt;) it took a while to figure out what went wrong in the model, since the resulting numbers (aside from 10 / str) look quite reasonable. &lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 11:43:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/strings-arithmetic-with-a-variant/m-p/13550815#M55536</guid>
      <dc:creator>mischa_spelt</dc:creator>
      <dc:date>2017-09-05T11:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Strings arithmetic with a Variant</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/strings-arithmetic-with-a-variant/m-p/13550816#M55537</link>
      <description>&lt;P&gt;In all the examples you have given, you are using a binary operator with a Variant and a non-variant (int or double) value. If the Variant is on the right, then the variant is first cast to a number. in the case of the string variant, that will always be zero. If the Variant is on the left, the Variant checks to see if it is a number type. If it is, it casts itself to a number and does the operation. If not, the operator will return the value on the right.&lt;/P&gt;&lt;P&gt;If both values are Variants, then both must be string or number types. In the string case, you can only add. If you are not adding strings, or if the types mismatch, you will get a null value.&lt;/P&gt;&lt;P&gt;This behavior is by design. &lt;A rel="user" href="https://answers.flexsim.com/users/207/anthony.j.html" nodeid="207"&gt;@anthony.johnson&lt;/A&gt; may have some further insight. As a way to catch this issue sooner, try to do Variant math rather than Variant/non-Variant math. This will produce null values, rather than numbers, if there is a type mismatch.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 18:13:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/strings-arithmetic-with-a-variant/m-p/13550816#M55537</guid>
      <dc:creator>JordanLJohnson</dc:creator>
      <dc:date>2017-09-06T18:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Strings arithmetic with a Variant</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/strings-arithmetic-with-a-variant/m-p/13550817#M55538</link>
      <description>&lt;P&gt;Thanks for the explanation Jordan. I guess what made the least sense to me was &lt;BR /&gt;  "If not, the operator will return the value on the right."&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 09:19:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/strings-arithmetic-with-a-variant/m-p/13550817#M55538</guid>
      <dc:creator>mischa_spelt</dc:creator>
      <dc:date>2017-09-07T09:19:36Z</dc:date>
    </item>
  </channel>
</rss>

