Skip navigation
Currently Being Moderated

Help with IF statement

May 14, 2013 1:10 PM

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


   value = G10;





            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

  • Currently Being Moderated
    May 14, 2013 9:04 PM   in reply to fsoender

    There are a few things wrong.
    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


    should be a string check


    if(value != null)




    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)



    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points