cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tehdeadhand
Level: Powered On

any ideas of adding numbers to textbox like a calculator

any ideas of how to add numbers to textbox like a calculator. so when press button 1  textbox= 1 press button 2 textbox = 12

thanks

calc.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Level 10

Re: any ideas of adding numbers to textbox like a calculator

Yes, use a context variable.

 

For example set the button 1 OnSelect property to

UpdateContext({MyNumberText: MyNumberText&"1"})

Do the same for all other number buttons and .

 

Have a Clear button to do this:

UpdateContext({MyNumberText: ""})

 

Set the text box's Text property to MyNumberText

 

If you need to use the number for calculations, then use Value(MyNumberText) to get a number value

View solution in original post

4 REPLIES 4
Meneghino
Level 10

Re: any ideas of adding numbers to textbox like a calculator

Yes, use a context variable.

 

For example set the button 1 OnSelect property to

UpdateContext({MyNumberText: MyNumberText&"1"})

Do the same for all other number buttons and .

 

Have a Clear button to do this:

UpdateContext({MyNumberText: ""})

 

Set the text box's Text property to MyNumberText

 

If you need to use the number for calculations, then use Value(MyNumberText) to get a number value

View solution in original post

Community Support Team
Community Support Team

Re: any ideas of adding numbers to textbox like a calculator

Hi Tehdeadhand,

 

The workaround @Meneghino has provided works perfectly, please try with it on your side.

 

For more details about PowerApps UpdateContentext function, please see this article for a reference:
https://powerapps.microsoft.com/en-us/tutorials/function-updatecontext/


Best regards,
Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
hpkeong
Level 10

Re: any ideas of adding numbers to textbox like a calculator

Hi @tehdeadhand

 

Back to Project Siena in 2015, courtesy PtrChovan, herewith I share a:

- Complete apps of making a calculator with all the codes and link

https://gallery.technet.microsoft.com/Siena-Simple-Calculator-5e5a8e3f

 

Variable is generated when update context is triggered and the variable is called in another updatecontext

 

 

1/ Create NumPad with buttons (1,2,3....)

 

2/ Add This code into each number

 

OnSelect= UpdateContext({buttonvalue:"1"}); If(CE=3, UpdateContext({equal:0, FN:buttonvalue, SN:"0"}), CE=1, UpdateContext({FN: FN&buttonvalue}), UpdateContext({SN: SN&buttonvalue})); If(CE=3, UpdateContext({CE: 1}))

 

3/ Change in the code above buttonvalue to match each button value

 

4/Create CE button and add this code into it

 

OnSelect= UpdateContext({CE: 1, equal:0, FN:"0", SN:"0"})

 

5/Create + Button with this code

 

OnSelect= UpdateContext({CE: 2, Math: "+"})

 

6/ Create - button with this code

 

OnSelect= UpdateContext({CE: 2, Math: "-"})

 

7/ Create = button with this code

 

OnSelect= UpdateContext({CE: 3, equal:If(Math="+", Value(FN)+Value(SN), Math="-",Value(FN)-Value(SN))})

 

8/Create label to display numbers with

 

Text= If(CE<=1, Value(FN), CE=2 && Value(SN)>0 ,Value(SN), CE=2 && Value(SN)=0 ,Value(FN), CE=3, equal)

 

FN= First No

SN = Second No

 

Untitled.png

 

Hope you like it.

hpkeong
PytByt
Level 8

Re: any ideas of adding numbers to textbox like a calculator

hi @hpkeong 

i already downloaded it, bu how i run this Calcualtor.siena ?

thanks.

pytbyt

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Kudoed Authors (Last 30 Days)
Users online (3,537)