Loading ...
Sorry, an error occurred while loading the content.
 

Re: What value of nothing can be used to satisfy an IF ?

Expand Messages
  • gmorlosky1
    Unfortunately double.NaN isn t nothing as it is actually N/A. So if I try to Concat that into a string, I don t end up with nothing but something. Oh well.
    Message 1 of 5 , Dec 1, 2012
      Unfortunately double.NaN isn't nothing as it is actually N/A. So if I try to Concat that into a string, I don't end up with nothing but something. Oh well.

      --- In TOS_thinkscript@yahoogroups.com, "Richard Houser" <rhouser@...> wrote:
      >
      > Double.NaN
      >
      >
      >
      > From: TOS_thinkscript@yahoogroups.com
      > [mailto:TOS_thinkscript@yahoogroups.com] On Behalf Of gmorlosky1
      > Sent: Friday, November 30, 2012 6:59 PM
      > To: TOS_thinkscript@yahoogroups.com
      > Subject: [TOS_thinkscript] What value of nothing can be used to satisfy an
      > IF ?
      >
      >
      >
      >
      >
      > I am trying to use IF and I keep getting messed up as I tried "" for my
      > nothing but get an error.
      > What is the equivalent of nothing when using numbers in an IF ?
      >
      > Error:
      > Wrong type cast: different types after then and else: double vs class
      > java.lang.String
      >
      > Example
      > ... (if IsNaN (Call_1000) then "" else Call_1000);
      >
    • Richard Houser
      You didn t mention that the logic statement was part of a string, as shown I assumed it was part of a def, rec, or plot. The problem is you re mixing data
      Message 2 of 5 , Dec 1, 2012

        You didn't mention that the logic statement was part of a string, as shown I assumed it was part of a def, rec, or plot. The problem is you're mixing data types, and the error message that was generated says, "Wrong type cast: different types after then and else: double vs class java.lang.String" is one of the few actually informational error messages in thinkscript ;-)

        So the problem is the data type mismatch between "" and Call_1000, where "" is type string and Call_1000 is type Double. If you're using this in a def, rec, or plot, then the solution is:

        def something = ( if IsNaN( Call_1000 ) then Double.NaN else Call_1000 )  # Both data elements are type double

        If you're using it in a string the solution is:

        AddLabel( yes, "Call_1000: " + (if IsNaN( Call_1000 ) then "" else AsText( Call_1000 )  );  # Both data elements are type string
        or
        AddLabel( !IsNaN( Call_1000 ), "Call_1000: " + Call_1000 );  # Eliminated one data type, impossible to have a mismatch


         

        From: TOS_thinkscript@yahoogroups.com [mailto:TOS_thinkscript@yahoogroups.com] On Behalf Of gmorlosky1
        Sent: Saturday, December 01, 2012 8:40 AM
        To: TOS_thinkscript@yahoogroups.com
        Subject: [TOS_thinkscript] Re: What value of nothing can be used to satisfy an IF ?

         

         

        Unfortunately double.NaN isn't nothing as it is actually N/A. So if I try to Concat that into a string, I don't end up with nothing but something. Oh well.

        --- In TOS_thinkscript@yahoogroups.com, "Richard Houser" <rhouser@...> wrote:
        >
        > Double.NaN
        >
        >
        >
        > From: TOS_thinkscript@yahoogroups.com
        > [mailto:TOS_thinkscript@yahoogroups.com] On Behalf Of gmorlosky1
        > Sent: Friday, November 30, 2012 6:59 PM
        > To: TOS_thinkscript@yahoogroups.com
        > Subject: [TOS_thinkscript] What value of nothing can be used to satisfy an
        > IF ?
        >
        >
        >
        >
        >
        > I am trying to use IF and I keep getting messed up as I tried "" for my
        > nothing but get an error.
        > What is the equivalent of nothing when using numbers in an IF ?
        >
        > Error:
        > Wrong type cast: different types after then and else: double vs class
        > java.lang.String
        >
        > Example
        > ... (if IsNaN (Call_1000) then "" else Call_1000);
        >

      • gmorlosky1
        Thanks greatly
        Message 3 of 5 , Dec 5, 2012
          Thanks greatly

          --- In TOS_thinkscript@yahoogroups.com, "Richard Houser" <rhouser@...> wrote:
          >
          > You didn't mention that the logic statement was part of a string, as shown I
          > assumed it was part of a def, rec, or plot. The problem is you're mixing
          > data types, and the error message that was generated says, "Wrong type cast:
          > different types after then and else: double vs class java.lang.String" is
          > one of the few actually informational error messages in thinkscript ;-)
          >
          > So the problem is the data type mismatch between "" and Call_1000, where ""
          > is type string and Call_1000 is type Double. If you're using this in a def,
          > rec, or plot, then the solution is:
          >
          > def something = ( if IsNaN( Call_1000 ) then Double.NaN else Call_1000 ) #
          > Both data elements are type double
          >
          > If you're using it in a string the solution is:
          >
          > AddLabel( yes, "Call_1000: " + (if IsNaN( Call_1000 ) then "" else AsText(
          > Call_1000 ) ); # Both data elements are type string
          > or
          > AddLabel( !IsNaN( Call_1000 ), "Call_1000: " + Call_1000 ); # Eliminated
          > one data type, impossible to have a mismatch
          >
          >
          >
          >
          >
          >
          > From: TOS_thinkscript@yahoogroups.com
          > [mailto:TOS_thinkscript@yahoogroups.com] On Behalf Of gmorlosky1
          > Sent: Saturday, December 01, 2012 8:40 AM
          > To: TOS_thinkscript@yahoogroups.com
          > Subject: [TOS_thinkscript] Re: What value of nothing can be used to satisfy
          > an IF ?
          >
          >
          >
          >
          >
          > Unfortunately double.NaN isn't nothing as it is actually N/A. So if I try to
          > Concat that into a string, I don't end up with nothing but something. Oh
          > well.
          >
          > --- In TOS_thinkscript@yahoogroups.com
          > <mailto:TOS_thinkscript%40yahoogroups.com> , "Richard Houser" <rhouser@>
          > wrote:
          > >
          > > Double.NaN
          > >
          > >
          > >
          > > From: TOS_thinkscript@yahoogroups.com
          > <mailto:TOS_thinkscript%40yahoogroups.com>
          > > [mailto:TOS_thinkscript@yahoogroups.com
          > <mailto:TOS_thinkscript%40yahoogroups.com> ] On Behalf Of gmorlosky1
          > > Sent: Friday, November 30, 2012 6:59 PM
          > > To: TOS_thinkscript@yahoogroups.com
          > <mailto:TOS_thinkscript%40yahoogroups.com>
          > > Subject: [TOS_thinkscript] What value of nothing can be used to satisfy an
          > > IF ?
          > >
          > >
          > >
          > >
          > >
          > > I am trying to use IF and I keep getting messed up as I tried "" for my
          > > nothing but get an error.
          > > What is the equivalent of nothing when using numbers in an IF ?
          > >
          > > Error:
          > > Wrong type cast: different types after then and else: double vs class
          > > java.lang.String
          > >
          > > Example
          > > ... (if IsNaN (Call_1000) then "" else Call_1000);
          > >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.