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.

Software ==> Power Apps  (13 exercises)
Version ==> Latest update
Topic ==> Formulae  (2 exercises)
Level ==> Average difficulty
Subject ==> Power BI training
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

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!

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:

Starter's orders button

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:

Race button

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).

Archibalda wins

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:

The 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:

Property Value
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!

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post