web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Help Creating Simple C...
Power Apps
Unanswered

Help Creating Simple Counter

(0) ShareShare
ReportReport
Posted on by 30

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

 

 

Categories:
I have the same question (0)
  • Verified answer
    CarlosFigueira Profile Picture
    on at

    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)
  • SqueezeOJ Profile Picture
    30 on at

    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

     

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard