Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub Addstudent_Click()
- Dim ID As String, Name As String, Grade As String
- Dim Test1 As Integer, Mid As Integer, Test2 As Integer, Final As Integer, Total As Integer
- Dim Percentage As Double
- Dim Flag As Boolean
- Dim i As Integer
- EmptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
- ID = IDText.Text
- Name = NameText.Text
- Test1 = T1Text.Text
- Mid = MidText.Text
- Test2 = T2Text.Text
- Final = FinalText.Text
- Total = Test1 + Mid + Test2 + Final
- Percentage = Total / 4
- If Percentage >= 86 Then
- Grade = "A"
- Else
- If Percentage >= 75 Then
- Grade = "B+"
- Else
- If Percentage >= 68 Then
- Grade = "B"
- Else
- If Percentage >= 60 Then
- Grade = "C"
- Else
- If Percentage >= 50 Then
- Grade = "D"
- Else
- Grade = "E"
- End If
- End If
- End If
- End If
- End If
- Flag = False
- i = 2
- Do While Cells(i, 1).Value <> ""
- 'MsgBox (Cells(i + 1, 1).Value)
- ' If the ID in row i is identical to ID From the TextBox is the form
- If Cells(i, 1).Value = ID Then
- 'Update THAT row in the table
- Gradesheet.Cells(i, 2) = Name
- Gradesheet.Cells(i, 3) = Test1
- Gradesheet.Cells(i, 4) = Mid
- Gradesheet.Cells(i, 5) = Test2
- Gradesheet.Cells(i, 6) = Final
- Gradesheet.Cells(i, 7) = Percentage
- Gradesheet.Cells(i, 8) = Grade
- Gradesheet.Range("A:H").Columns.AutoFit
- Flag = True
- End If
- i = i + 1
- Loop
- 'If there was NO updated row
- If Flag = False Then
- 'Add a new row
- Gradesheet.Cells(EmptyRow, 1) = ID
- Gradesheet.Cells(EmptyRow, 2) = Name
- Gradesheet.Cells(EmptyRow, 3) = Test1
- Gradesheet.Cells(EmptyRow, 4) = Mid
- Gradesheet.Cells(EmptyRow, 5) = Test2
- Gradesheet.Cells(EmptyRow, 6) = Final
- Gradesheet.Cells(EmptyRow, 7) = Percentage
- Gradesheet.Cells(EmptyRow, 8) = Grade
- Gradesheet.Range("A:H").Columns.AutoFit
- End If
- End Sub
- Private Sub DeleteStudent_Click()
- Dim Flag As Boolean, i As Integer, ID As String
- Dim Found As Boolean
- Found = False
- ID = IDText.Text
- Flag = False
- i = 1
- Do While Cells(i, 1).Value <> ""
- ' If the ID in row i is identical to ID From the TextBox is the form
- If Cells(i, 1).Value = ID Then
- 'Modify the row with the next
- Found = True
- 'Indicate that there EXISTS a row with the name ID
- End If
- If Found = True Then
- Gradesheet.Cells(i, 1) = Gradesheet.Cells(i + 1, 1)
- Gradesheet.Cells(i, 2) = Gradesheet.Cells(i + 1, 2)
- Gradesheet.Cells(i, 3) = Gradesheet.Cells(i + 1, 3)
- Gradesheet.Cells(i, 4) = Gradesheet.Cells(i + 1, 4)
- Gradesheet.Cells(i, 5) = Gradesheet.Cells(i + 1, 5)
- Gradesheet.Cells(i, 6) = Gradesheet.Cells(i + 1, 6)
- Gradesheet.Cells(i, 7) = Gradesheet.Cells(i + 1, 7)
- Gradesheet.Cells(i, 8) = Gradesheet.Cells(i + 1, 8)
- End If
- i = i + 1
- Loop
- End Sub
- Private Sub IDTEXT_Change()
- Dim Flag As Boolean, i As Integer, ID As String
- ID = IDText.Text
- Flag = False
- i = 2
- Do While Cells(i, 1).Value <> ""
- ' If the ID in row i is identical to ID From the TextBox is the form
- If Cells(i, 1).Value = ID Then
- 'Update the OTHER text boxes
- NameText.Text = Gradesheet.Cells(i, 2)
- T1Text.Text = Gradesheet.Cells(i, 3)
- MidText.Text = Gradesheet.Cells(i, 4)
- T2Text.Text = Gradesheet.Cells(i, 5)
- FinalText.Text = Gradesheet.Cells(i, 6)
- 'Indicate that there EXISTS a row with the name ID
- Flag = True
- End If
- i = i + 1
- Loop
- 'If there was NO updated row
- If Flag = False Then
- 'Empty the other text boxes
- NameText.Text = ""
- T1Text.Text = ""
- MidText.Text = ""
- T2Text.Text = ""
- FinalText.Text = ""
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement