- Access exercises (91)
- C# exercises (79)
- Excel exercises (278)
- Power Apps exercises (13)
- Power Automate exercises (18)
- Power BI exercises (139)
- Power Platform exercises ()
- Python exercises (28)
- Report Builder exercises (141)
- SQL exercises (198)
- SSAS exercises (51)
- SSIS exercises (46)
- SSRS exercises (99)
- VBA exercises (85)
- Visual Basic exercises (46)
POWER BI EXERCISES▼
POWER APPS EXERCISES▼
Power Apps | Formulae exercise | Create a horse race, using the Y properties of images
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
The aim of this exercise is to create a two-horse race! Starty by creating a new canvas tablet app, and save it as Racecourse.
Add two images based on the files in the above folder:
|Insert each image ...||... then assign it to a file.|
You should now have two horses!
Who is your money on? Give each image a sensible name, so you can refer to it easily.
Add a button to put the horses under starter's orders:
Clicking on the button should position the horses 50 pixels beneath the button, ready to start racing. Do this by setting the values of variables, then assigning the Y properties of each image to these variable values.
Be very careful from this point onwards not to drag your horses around the screen - doing so will override the Y property you've set with a constant number. This is Power Apps' most irritating feature!
Add a Race button which randomly advances one horse or another with equal probability:
Test the value of Rand(), a function which returns a random number between 0 and 1. If this is less than 0.5, set Anastasia's variable to be itself plus 50; otherwise, do the same for Archibalda's variable.
Things are going well, but the horses disappear off the bottom of the screen. Set a winning label for each horse to become visible when the horse gets within a given number of pixels of the bottom of the screen (you'll need to use Parent.Height for each label to get the height of the screen it belongs to in order to help determine when this becomes true).
A victory for Archibalda! As a bonus, you could disable the Race button as soon as either horse wins (that is, set its DisplayMode to Disabled when the Visible property of either winning label is true).
If you still have time and energy, you could automate the race by adding a timer:
When everything is working, you can hide the timer - the user doesn't need to see it.
Set the following properties for the timer:
|Duration||1000 (ie 1 second; when everything is working you can reduce this to 100 to speed up your race!).|
|OnTimerStart||The same action as you assigned to the Race button previously, to advance one horse or the other randomly.|
|Repeat||true (every second you want the timer to restart, to advance a horse another square).|
|Start||IfStart (a variable which should be set to false when you put the horse's under starter's orders, and true when you start the race).|
|Reset||IfReset (a variable which should be set to true as soon as either winning message label becomes visible).|
You should now be ready to run simulations of your race, and start taking bets!