ALL SOFTWARE EXERCISES
- EXERCISES HOME PAGE (749)
- Access 2010 (66)
- Access VBA Macros (17)
- Advanced VBA (29)
- ASP.NET MVC (0)
- ASP.NET webforms - C# (25)
- ASP.NET webforms - VB (27)
- Excel 2010 (83)
- Excel 2013 (10)
- Excel VBA Macros (38)
- Power BI - Excel 2013 (23)
- Power BI Desktop (0)
- PowerPivot 2010 (26)
- Report Builder 3.0 (42)
- SQL (115)
- SSAS - multidimensional (21)
- SSAS - tabular (29)
- SSIS Integration Services (18)
- SSRS Reporting Services (53)
- Visual Basic 2010 (42)
- Visual C Sharp 2010 (65)
- WPF - Visual C# (20)
ADVANCED VBA EXERCISES
Exercise: Use shapes to create a simulation of a Formula One race
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.
The answer to the exercise will be included and explained if you attend the Wise Owl course listed below!
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.
It's easiest to do this exercise in two parts: first draw the starting grid, then run the race.
To start the race, first create a new workbook, and write a macro (using the images in the above folder) to draw autoshapes at the start of the first 4 rows of a spreadsheet:
The cars are 40 points wide, 30 points high and begin 20 points in from the left of their cells and 10 points down from the top. The ColumnWidth of each column is 15, and the RowHeight of each row is 50.
The easiest way to draw the cars is to draw a basic rectangular autoshape (type 1), then run a line of code like this to apply a picture to it:
When you've got the grid set up, it's time to run the race! Write a second macro to loop until a car has won (ie reached column H). For each time round the loop, you could display a message box to enable you to see what's going on:
Clicking on the message box should run the next move, which should advance one of the four cars (chosen at random) one cell. The answer uses the expression Int(Math.Rnd() * 4) + 1 to choose a random car number.
Here's what your screen might look like after running a race:
Car 4 has won, and you should report this fact with a message displayed on screen!
When you've got this working, save this workbook as Chequered flag, then close it down.