Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Public PassTotal = 0
- ' Enum Used in all the comboBoxes to provide the user with a choice
- Public Enum Achieved
- Fail = 0
- Pass = 70
- Merit = 80
- Distinction = 90
- End Enum
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- ' OK so lets set up all our comboBoxes
- SetUpComboBoxes(Me)
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- ' this is where we are going to do all the work
- PassTotal = 0 ' reset the initial value of Total Score to zero]
- ' sum up all the selected values...
- TextBox1.Text = CalculatePassTotal(Me) ' remember the enum at the top [Achieved]... we are summing those values that have been selected
- ' we have the total so get the Grade
- CalculateOverallGrade(PassTotal)
- ' now display it
- TextBox2.Text = Grade.OverallGradeProperty
- TextBox3.Text = Grade.GradePointsProperty
- TextBox4.Text = Val(Grade.UcasPointsProperty)
- End Sub
- Public Function CalculatePassTotal(ByVal ThisForm As Control)
- ' again, loop though all the controls on the form
- For Each ctrl As Control In ThisForm.Controls
- If TypeOf ctrl Is ComboBox Then ' if this control is a ComboBox
- PassTotal += CType(ctrl, ComboBox).SelectedValue ' add the selected value [Achieved Enum] to our running total [PassTotal]
- End If
- Next ctrl
- Return PassTotal ' return PassTotal
- End Function
- Public Sub CalculateOverallGrade(pt As Integer) 'As Grade
- 'now use PassTotal value to determine the grade (check these values, the first few looked a bit dodgy so i changed them)
- Select Case pt
- Case Is < 1260
- Grade.OverallGradeProperty = "Ungraded"
- Grade.GradePointsProperty = "0"
- Grade.UcasPointsProperty = 0
- Case 1260 To 1300
- Grade.OverallGradeProperty = "PPP"
- Grade.GradePointsProperty = "108-131"
- Grade.UcasPointsProperty = 120
- Case 1301 To 1339
- Grade.OverallGradeProperty = "MPP"
- Grade.GradePointsProperty = "132-155"
- Grade.UcasPointsProperty = 160
- Case 1340 To 1379
- Grade.OverallGradeProperty = "MMP"
- Grade.GradePointsProperty = "156-179"
- Grade.UcasPointsProperty = 200
- Case 1380 To 1419
- Grade.OverallGradeProperty = "MMM"
- Grade.GradePointsProperty = "180-203"
- Grade.UcasPointsProperty = 240
- Case 1420 To 1459
- Grade.OverallGradeProperty = "DMM"
- Grade.GradePointsProperty = "204-227"
- Grade.UcasPointsProperty = 280
- Case 1460 To 1499
- Grade.OverallGradeProperty = "DDM"
- Grade.GradePointsProperty = "228-251"
- Grade.UcasPointsProperty = 320
- Case 1500 To 1529
- Grade.OverallGradeProperty = "DDD"
- Grade.GradePointsProperty = "252-275"
- Grade.UcasPointsProperty = 360
- Case 1530 To 1559
- Grade.OverallGradeProperty = "D*DD"
- Grade.GradePointsProperty = "276-299"
- Grade.UcasPointsProperty = 380
- Case 1560 To 1589
- Grade.OverallGradeProperty = "D*D*D"
- Grade.GradePointsProperty = "300-323"
- Grade.UcasPointsProperty = 400
- Case Is >= 1590
- Grade.OverallGradeProperty = "D*D*D*"
- Grade.GradePointsProperty = "324-347"
- Grade.UcasPointsProperty = 420
- Case Else
- End Select
- End Sub
- Public Sub SetUpComboBoxes(ByVal ThisForm As Control)
- ' this function loops round all of the controls on this form and sets some properties for each of our 18 ComboBoxes
- For Each ctrl As Control In ThisForm.Controls
- If TypeOf ctrl Is ComboBox Then
- ' This is cool, we are pointing the combobox at an ENUM [Achieved] for its data source
- CType(ctrl, ComboBox).DataSource = System.Enum.GetValues(GetType(Achieved)) ' no need to add each item individually just point and go!!
- CType(ctrl, ComboBox).SelectedIndex = 0 ' set the initial selected item to 0 (Fail)
- ' OK, this next line is a delegate... what it is saying is this... whenever the SelectedValueChanged changes in ANY of the
- ' ComboBoxes call the ClearTextBoxes Sub
- AddHandler CType(ctrl, ComboBox).SelectedValueChanged, AddressOf ClearTextBoxes ' you can take this line out if you don't want to use it
- My.Settings.Save()
- End If
- Next ctrl
- End Sub
- Private Sub ClearTextBoxes(sender As Object, e As EventArgs)
- ' this function loops round all of the controls on this form and clears all the TextBoxes
- For Each ctrl As Control In Me.Controls
- If TypeOf ctrl Is TextBox Then
- CType(ctrl, TextBox).Text = "" ' set the initialy selected item to -1 (nothing)
- End If
- Next ctrl
- End Sub
- End Class
- Public Module Grade
- ' this is a simple Module to represent a single grade. Straight forward really
- Private GradePoints As String
- Public Property GradePointsProperty() As String
- Get
- Return GradePoints
- End Get
- Set(ByVal value As String)
- GradePoints = value
- End Set
- End Property
- Private OverallGrade As String
- Public Property OverallGradeProperty() As String
- Get
- Return OverallGrade
- End Get
- Set(ByVal value As String)
- OverallGrade = value
- End Set
- End Property
- Private UcasPoints As Integer
- Public Property UcasPointsProperty() As Integer
- Get
- Return UcasPoints
- End Get
- Set(ByVal value As Integer)
- UcasPoints = value
- End Set
- End Property
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement