Public Class Form1 Const ptsForWin As Integer = 3 Const ptsForDraw As Integer = 1 Const ptsForLoss As Integer = 0 ' General Function for Validating any integer ' Parameters: ' text - would normally be passed the text box to be validated's text property - Input ' val - the integer converted from the text - Output ' min - the lowest acceptable value for the input - Input ' max - the highest acceptable value for the input - Input ' what - a string indicating what is being validated - used for making error messages specific - Input ' Returns ' boolean indicating whether the text had a valid value ' it will be false if the input text was non-numeric, decimal, or outside the acceptable range Private Function validateInteger(ByVal text As String, ByRef val As Integer, ByVal min As Integer, ByVal max As Integer, ByVal what As String) As Boolean ' try converting input to integer Dim isConverted As Boolean isConverted = Integer.TryParse(text, val) If isConverted Then ' string was converted successfully - check if in range If val >= min AndAlso val <= max Then Return True Else ' outside of range - put out error msg MsgBox(what & " must be between " & min & " and " & max) Return False End If Else ' conversion unsuccessful - put out error msg MsgBox(what & " must be a whole number") Return isConverted End If End Function ' calculate points for a team based on their wins losses and ties. ' constants are used for the number of points for each Private Function calcPts(ByVal wins As Integer, ByVal losses As Integer, ByVal draws As Integer) As Integer Dim points As Integer points = wins * ptsForWin + losses * ptsForLoss + draws * ptsForDraw Return points End Function ' Handle all processing for a given team ' Parameters: ' winStr - Input string holding number of wins - would normally be passed the text property of the text box holding the number of wins ' lossStr - Input string holding number of losses - would normally be passed the text property of the text box holding the number of losses ' drawStr - Input string holding number of draws - would normally be passed the text property of the text box holding the number of draws ' temaNum - Input string holding the team number being proccessed - to be used to personalize any error messages ' ptsStr - Output string holding the number of points earned by the team being processed ' - typically would be passed the text property of the text box to hold the points in the GUI Private Sub processTeam(ByVal winStr As String, ByVal lossStr As String, ByVal drawStr As String, ByVal teamNum As String, ByRef ptsStr As String) Dim isConvertedWins As Boolean Dim isConvertedLosses As Boolean Dim isConvertedDraws As Boolean Dim wins As Integer Dim losses As Integer Dim draws As Integer Dim points As Integer ' check team's win, loss, and draw inputs to see if they are valid isConvertedWins = validateInteger(winStr, wins, 0, 6, "Team " & teamNum & " Wins") isConvertedLosses = validateInteger(lossStr, losses, 0, 6, "Team " & teamNum & " Losses") isConvertedDraws = validateInteger(drawStr, draws, 0, 6, "Team " & teamNum & " Draws") ' only go on if all input info is valid If isConvertedWins AndAlso isConvertedLosses AndAlso isConvertedDraws Then ' determine number of points earned by team and display in results text box points = calcPts(wins, losses, draws) ptsStr = points.ToString() End If End Sub ' clear all numerics - wins, losses, draws and points for all teams Private Sub clearResults() txtWins1.Text = "0" txtWins2.Text = "0" txtWins3.Text = "0" txtWins4.Text = "0" txtLosses1.Text = "0" txtLosses2.Text = "0" txtLosses3.Text = "0" txtLosses4.Text = "0" txtDraws1.Text = "0" txtDraws2.Text = "0" txtDraws3.Text = "0" txtDraws4.Text = "0" txtPts1.Text = "0" txtPts2.Text = "0" txtPts3.Text = "0" txtPts4.Text = "0" End Sub Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click Me.Close() End Sub Private Sub btnRestart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestart.Click clearResults() End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click ' clear numerics and team names clearResults() txtTeam1.Clear() txtTeam2.Clear() txtTeam3.Clear() txtTeam4.Clear() End Sub Private Sub btnScore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScore.Click ' handle all four teams info processTeam(txtWins1.Text, txtLosses1.Text, txtDraws1.Text, "1", txtPts1.Text) processTeam(txtWins2.Text, txtLosses2.Text, txtDraws2.Text, "2", txtPts2.Text) processTeam(txtWins3.Text, txtLosses3.Text, txtDraws3.Text, "3", txtPts3.Text) processTeam(txtWins4.Text, txtLosses4.Text, txtDraws4.Text, "4", txtPts4.Text) End Sub End Class