2 Replies Latest reply on May 22, 2013 10:13 PM by fsoender

    Help with IF statement

    fsoender

         public var x:Object;   
         public var value:String;

       

         value = G10;

       

       

       

                   if(value)
          
                  {

                  x = value;
          
           
                 if (x<G10)      
                
                {
           
                 Code here...
                 
                }

       


      Why cant I write it like this "if (x<G10)"?

      Im trying to read a value from a microcontroller, that have the letter "G" infront of a number. The code works if I use only numbers like this: if (x<10).

      Compiler wont accept it, comes with this ERROR:

       

      Multiple markers at this line:

      -1120: Access of undefined property G10.

      -1 changed line

        • 1. Re: Help with IF statement
          fB3 Level 2

          There are a few things wrong.
          First,
          value = G10;
          needs to be in quotes if G10 is really a string
          value = "G10";
          Otherwise the compiler will think it an undeclared variable.

           

          Next, this is a boolean true / false
          if(value)

           

          should be a string check

           

          if(value != null)

           

          Next,

           

          x = value;

           

          That is a value of an Object to a String.

           

          Could be

           

          x.value = value;

           

          And last,
          if ( x < G10)
          this is incorrect because the less than sign wont work
          with strings unless the are a numeric value and using parseFloat or parsInt to compare them

           

          This would be in the ball park.

           

          if ( x.value != "G10")

           

          or if both values were numeric you could use

           

          if ( parseFloat(x.value) < 10)

           

          HTH

          • 2. Re: Help with IF statement
            fsoender Level 1

            Thanks!