- 02-07-2013, 03:50 PM
Thread Author #1
Simple QML Math Problem
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-2013, 04:06 PM #3
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-2013, 04:22 PM
Thread Author #4
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-2013, 04:37 PM #5
- 02-07-2013, 04:43 PM
Thread Author #6
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-2013, 06:36 PM
Thread Author #7
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-08-2013, 12:17 AM #8
Looks kinda like java script, in which case you could do (if element != 'NaN')...
Posted using CrackBerry App on BB10 - 02-08-2013, 08:22 AM #9
Similar Threads
-
BB 9800 Torch and Simple Mobile compatibility problem
By guru9800BB in forum Simple MobileReplies: 3Last Post: 09-13-2012, 09:34 AM -
Need some help with this little math problem...about bb traffic
By editionfws in forum Rehab & Off-Topic LoungeReplies: 14Last Post: 08-06-2012, 11:06 AM -
Is a math problem or patternlock alarm available?
By Ben34 in forum Storm 3rd Party AppsReplies: 11Last Post: 07-25-2009, 09:45 PM -
Simple Problem-Can't Figure It out
By davidmogentale in forum BlackBerry Curve 83xxReplies: 3Last Post: 08-01-2008, 09:43 AM -
Simple Book Player Problem
By Brother_Jebadiah in forum BlackBerry OS AppsReplies: 0Last Post: 04-09-2008, 01:14 PM

Reply


















