Question
Please complete using Microsoft Visual Basic for Applications (VBA) Programming Language. Part A: Create a simulation for one pair of teams - Create a simple
Please complete using Microsoft Visual Basic for Applications (VBA) Programming Language.
Part B: Run the simulation for all pairs of teams
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Option Explicit Option Base 1 ' **** did you remember option Base 1
' ******** DSS 620 Template ---- Created by John A. Michl jmichl@sju.edu ******** ' ** ' ** Module 5 Exercise 2 Template 1.5 ' ** Template Revision: 6/8/2018 by John A. Michl
' ** Student comments should use apostrophe only ' ** ' ** Assignment modified by STUDENT NAME on DATE ' ** ' ******************************************************************************
Sub BracketSimulation()
' **** All variables are provided; use only these variables Dim i As Integer ' counter for For Next loop Dim intGame As Integer ' game number (e.g. game 1 = seed 1 vs 16) Dim nTeams As Integer ' number of teams in bracket Dim intTrials As Integer ' number of simulations per pair
Dim nTeam1 As Integer ' temporarily hold index number for team 1 Dim nTeam2 As Integer ' temporarily hold index number for team 2
Dim sngMeas1 As Single ' temporarily hold performance measure for team 1 Dim sngMeas2 As Single ' temporarily hold performance measure for team 2
Dim sngSDev1 As Single ' temporarily hold standard deviation for team 1 Dim sngSDev2 As Single ' temporarily hold standard deviation for team 2
Dim nWins1 As Integer ' temporarily hold number of wins for team 1 Dim nWins2 As Integer ' temporarily hold number of wins for team 2
nTeams = 16 ' variable to enable other size brackets,
' clear old values With Range("Bracket_anchor") Range(.Offset(1, 2), .Offset(8, 8)).ClearContents End With
MsgBox "Values cleared. Ready to run simulation."
'***** NOTE: Part A will have one loop that loops through the pairs of teams '***** Part B will add a loop that will run a set number of trials (nTrials) between ' each pair of teams.
'******* Run simulation that runs one game for each pair
'>>
' **** Initialize nWins1 and nWins2 to reset to 0 in prep for For/Next loop '>>
' **** Retrieve index numbers for teams 1 and 2 from Bracket sheet
'>>>>>RETRIEVE INDEX NUMBERS
' **** Retrieve athletic measure (column L) and standard deviation (M) from Data sheet ' **** assign to sngMeas1, sngSDev1, sngMeas2, sngDev2
'vvvvvvvvv Your code below
'>>> RETRIEVE MEASURES
'^^^^^^^^ Your code above
' **** Use the NormDist function for each team, compare and pick a winner ' Increment the appropriate nWins1 or nWins2 variable.
' vvvvvvv Your code below
'>>>>>COMPARE NORMDIST FUNCTIONS TO PICK WINNER
' ^^^^^^^ Your code above
' **** Output the team names, nWins1, nWins2, sngMeas1, and sngMeas2 to appropriate row in Brackets sheet
' vvvvvv Your code below
'>>>> OUTPUT RESULTS
' ^^^^^^ Your code above
' ^^^ Close For/Next loop above for Part A directly above. Close Part B loop further up.
End Sub
Function NormDist(measure As Single, measure_SD As Single) As Single ' This function will return a value to the calling sub ' It will will use the worksheet function NORM.INV which requires three parameters. ' Parameter 1: probability -- uses RND to generate a random probability ' Parameter 2: mean -- this would be the measure passed over from the calling sub ' Parameter 3: standard deviation, this would be standard deviation of the mean ' and should be passed over from the calling sub.
' Initialize the random number generator Randomize
NormDist = Application.WorksheetFunction.Norm_Inv(Rnd, measure, measure_SD)
End Function |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started