1. Ninjatogo's Avatar
    Hi all,
    I'm practicing building apps for BB10 using the Cascades framework, recently I ran into a problem when trying to do some simple addition and subtraction in my QML project. I've got a set of input boxes (prc0-9) that are blank by default (with hint text, but I can't imagine that would affect the results here). From my observations everything works perfectly if there is a number in all the input boxes, but if there is a single blank I get, "nan", in the output box (prof.text). I'd be grateful if someone could help me out here.

    Code:
    onClicked: {
    			var int0 = parseInt(prc0.text);
    			var int1 = parseInt(prc1.text);
    			var int2 = parseInt(prc2.text);
    			var int3 = parseInt(prc3.text);
    			var int4 = parseInt(prc4.text);
    			var int5 = parseInt(prc5.text);
    			var int6 = parseInt(prc6.text);
    			var int7 = parseInt(prc7.text);
    			var int8 = parseInt(prc8.text);
    			var int9 = parseInt(prc9.text);
    			var int10 = int0+int1+int2+int3
    					+int4+int5+int6+int7
    					+int8+int9;
    			var intbudg = parseInt(budg.text);
    						if ( int10 > intbudg )
    							{req.text = int10 - intbudg}
    						else
    							{req.text = "0"
    							prof.text = intbudg - int10}
    }
    02-07-13 03:50 PM
  2. PCMC's Avatar
    I believe 'nan' is short for 'not a number'. I would bet when you try to add a blank instead of an integer the result is 'nan'. Maybe you can default the value in the boxes to 0?

    *disclaimer* I know nothing of QML.
    Ninjatogo likes this.
    02-07-13 04:06 PM
  3. mikeo007's Avatar
    You need to add some logic to check if there is a number in each of the boxes.
    If there isn't a number, then you can do something like set it to 0 or prompt the user to fill in all boxes before tapping the button.

    NaN stands for "Not a Number"
    02-07-13 04:06 PM
  4. Ninjatogo's Avatar
    I see; I don't want to fill the boxes with 0 and lose my fancy hint text so I'll trying making a quick check for blanks.
    02-07-13 04:22 PM
  5. mikeo007's Avatar
    I see; I don't want to fill the boxes with 0 and lose my fancy hint text so I'll trying making a quick check for blanks.
    You'll want to check for anything that's not a number, in case the user accidentally puts letters in the boxes.
    Ninjatogo likes this.
    02-07-13 04:37 PM
  6. Ninjatogo's Avatar
    I was simply going to check if it's blank and change the corresponding variable to 0. I don't know how to check the string for letters, but I'll do some searching.
    02-07-13 04:43 PM
  7. Ninjatogo's Avatar
    I finally finished it. I decided to restrict the input mode to numbers and punctuation, so they can't type letters and put in an if statement that changes the field text to 0 if the field is blank on click. Thanks for the help!
    02-07-13 06:36 PM
  8. SCrid2000's Avatar
    Looks kinda like java script, in which case you could do (if element != 'NaN')...

    Posted using CrackBerry App on BB10
    Ninjatogo likes this.
    02-08-13 12:17 AM
  9. mikeo007's Avatar
    Looks kinda like java script, in which case you could do (if element != 'NaN')...

    Posted using CrackBerry App on BB10
    Or if you're using C++, include cmath and use: isnan(yournumber)
    It will return true if it's not a number.
    Ninjatogo likes this.
    02-08-13 08:22 AM

Similar Threads

  1. BB 9800 Torch and Simple Mobile compatibility problem
    By guru9800BB in forum Simple Mobile
    Replies: 3
    Last Post: 09-13-12, 09:34 AM
  2. Need some help with this little math problem...about bb traffic
    By editionfws in forum Rehab & Off-Topic Lounge
    Replies: 14
    Last Post: 08-06-12, 11:06 AM
  3. Is a math problem or patternlock alarm available?
    By Ben34 in forum Storm 3rd Party Apps
    Replies: 11
    Last Post: 07-25-09, 09:45 PM
  4. Simple Problem-Can't Figure It out
    By davidmogentale in forum BlackBerry Curve 83xx
    Replies: 3
    Last Post: 08-01-08, 09:43 AM
  5. Simple Book Player Problem
    By Brother_Jebadiah in forum BlackBerry OS Apps
    Replies: 0
    Last Post: 04-09-08, 01:14 PM
LINK TO POST COPIED TO CLIPBOARD