Dealing with numbers

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
O.R-Dev
Posts: 2
Joined: Wed Sep 19, 2012 10:25 pm

Dealing with numbers

Post by O.R-Dev » Wed Sep 19, 2012 10:31 pm

Hi guys. Im creating a tool for operations research (early stages).
2 issues have put a complete stop to my work. I was wondering if anyone knew how to bring up only the numeric keypad for a text entry field.
and secondly how to make calculations using the number in that field with other numbers in other fields.
any help would be greatly appreciated

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10324
Joined: Wed May 06, 2009 2:28 pm

Re: Dealing with numbers

Post by dunbarx » Wed Sep 19, 2012 11:20 pm

Hi.

Do you mean you want to lock out the ability of the user to use the numeric keys overlying the standard keyboard?

Check out the "rawKeyUp" message. You can trap this, and the parameter passed is different for the keys in the numeric keypad as opposed to the keys above the ordinary keypad.

As for doing calculations, nothing could be simpler. And by that I mean that it will be an adventure filled with both peril and triumph.

How experienced are you? Write back if you need examples of either of the things I mentioned.

Craig Newman

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10324
Joined: Wed May 06, 2009 2:28 pm

Re: Dealing with numbers

Post by dunbarx » Wed Sep 19, 2012 11:48 pm

It occurs to me you already could use examples, or you would not have phrased your query the way you did.

In a new stack, make a field. Name this "myField". Place the following handler in the card script:

Code: Select all

on rawKeyUp var
   switch var
      case 65432 --keyCode for "6"
         put "6" after fld "myField"
         break
      case 65429 --keyCode for "7"
         put "7" after fld "myField"
         break
   end switch
end rawKeyUp

on keyDown
end keyDown
Now you must examine this. What is going on? And how can I figure out a way to handle all the digits? Is there a more compact way to manage the keyCodes?

In your stack, make another field. Name this "tAnswer". Make a button. Name this "calc". In the button script:

Code: Select all

on mouseUp
 put fld "myField" + 10 into fld "tAnswer"
end mouseUp
You can, at least at this point, be able to load 6's and 7's into field "myField". When you press the button, you add 10 to that value, and place the sum in field "tResult"

Now get going, and make this all work. Write back at any time for more help. Really. Anytime.

Craig Newman

O.R-Dev
Posts: 2
Joined: Wed Sep 19, 2012 10:25 pm

Re: Dealing with numbers

Post by O.R-Dev » Thu Sep 20, 2012 12:35 am

dunbarx wrote:It occurs to me you already could use examples, or you would not have phrased your query the way you did.

In a new stack, make a field. Name this "myField". Place the following handler in the card script:

Code: Select all

on rawKeyUp var
   switch var
      case 65432 --keyCode for "6"
         put "6" after fld "myField"
         break
      case 65429 --keyCode for "7"
         put "7" after fld "myField"
         break
   end switch
end rawKeyUp

on keyDown
end keyDown
Now you must examine this. What is going on? And how can I figure out a way to handle all the digits? Is there a more compact way to manage the keyCodes?

In your stack, make another field. Name this "tAnswer". Make a button. Name this "calc". In the button script:

Code: Select all

on mouseUp
 put fld "myField" + 10 into fld "tAnswer"
end mouseUp
You can, at least at this point, be able to load 6's and 7's into field "myField". When you press the button, you add 10 to that value, and place the sum in field "tResult"

Now get going, and make this all work. Write back at any time for more help. Really. Anytime.

Craig Newman
Thanks alot guys. I prob should have done a better job of asking my question.

i figured how to use the data in fields to do calculations using different forms of this exampe
on mouseUp
put field "s11" + field "s21" + field "s31" into field "total"

it works fine on the iphone simulator. However when the user in inputting the data the regular keyboard pops up . The user then has to switch to numbers. I would to make the default numpad to pop up instead of the keypad because there is no use for letters in the application .

Adrian
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 79
Joined: Wed Jul 11, 2012 5:03 pm

Re: Dealing with numbers

Post by Adrian » Thu Sep 20, 2012 6:23 pm

If you make your fields iOS native ones (which means creating them via script), then you can define the default keyboard using keyboardType. See the LiveCode iOS Relelase Notes for details (under "Inut control - UITextField").

Cheers,

Adrian

anmldr
Posts: 459
Joined: Tue Sep 11, 2012 11:13 pm

Re: Dealing with numbers

Post by anmldr » Sat Sep 22, 2012 12:15 am

Try using this to set the keyboard to a numeric one that has a decimal

Code: Select all

set iphoneSetKeyboardType "decimal"
or the numeric one

Code: Select all

set iphoneSetKeyboardType "numeric"
Linda

Post Reply