cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SqueezeOJ
Frequent Visitor

Help Creating Simple Counter

Hello,

 

I'm trying to create a very simple counter in PowerApps that looks like this:

 

PowerApps_Simple_Counter.png

Here's how I'd like it to work:

  • Current count will be stored in variable named myCount
  • txtCount.text is set to myCount
  • btnUp.onSelect will increment txtCount with Set(myCount,myCount+1)
  • btnDown.onSelect will decrement txtCount with Set(myCount,myCount11)
  • btnZero.onSelect will set txtCount to 0 (zero) with Set(myCount,0)
  • txtCount should never go below 0 (zero) or above 10.  So, it must stay between 0 to 9

My Problems:

  1. Can't figure out how to set myCount to 0 (zero) when the App begins.  I'm using App.onStart = Set(myCount,0), but it doesn't do anything - and UpdateContext gives a warning.
  2. How do you test the value of myCount and control it with only the very simple events we have available?  I guess, I don't understand where the program flow and logic control would go for a slightly complex application like this.  Any insight is greatly appreciated.

Thank you for your time!

Jason

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

You're already doing the right thing in initializing the counter:

Screen1.OnStart: Set(myCount, 0)

But you need to close and reopen the app (i.e., save it to your computer, then open it) to have the OnStart executed.

 

To test the value, you can use the If function in your buttons:

btnUp.OnSelect: If(myCount < 9, Set(myCount, myCount + 1))
btnDown.OnSelect: If(myCount > 0, Set(myCount, myCount - 1))

Another option is to keep the formula as is, but disable the buttons if they cannot be pressed. The properties would look something like those:

btnUp.OnSelect: Set(myCount, myCount + 1)
btnDown.OnSelect: Set(myCount, myCount - 1)
btnUp.DisplayMode: If(myCount < 9, DisplayMode.Edit, DisplayMode.Disabled)
btnDown.DisplayMode: If(myCount > 0, DisplayMode.Edit, DisplayMode.Disabled)

View solution in original post

2 REPLIES 2
CarlosFigueira
Power Apps
Power Apps

You're already doing the right thing in initializing the counter:

Screen1.OnStart: Set(myCount, 0)

But you need to close and reopen the app (i.e., save it to your computer, then open it) to have the OnStart executed.

 

To test the value, you can use the If function in your buttons:

btnUp.OnSelect: If(myCount < 9, Set(myCount, myCount + 1))
btnDown.OnSelect: If(myCount > 0, Set(myCount, myCount - 1))

Another option is to keep the formula as is, but disable the buttons if they cannot be pressed. The properties would look something like those:

btnUp.OnSelect: Set(myCount, myCount + 1)
btnDown.OnSelect: Set(myCount, myCount - 1)
btnUp.DisplayMode: If(myCount < 9, DisplayMode.Edit, DisplayMode.Disabled)
btnDown.DisplayMode: If(myCount > 0, DisplayMode.Edit, DisplayMode.Disabled)

Thanks for the solution, Carlos!

 

I used the DisplayMode approach.  Here's what it looks like now:

At 9 btnUp is disabledAt 9 btnUp is disabled

At 0 btnDown is disabledAt 0 btnDown is disabled

 

 

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,885)