Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Private Sub Addstudent_Click()
  3.  
  4.         Dim ID As String, Name As String, Grade As String
  5.         Dim Test1 As Integer, Mid As Integer, Test2 As Integer, Final As Integer, Total As Integer
  6.         Dim Percentage As Double
  7.         Dim Flag As Boolean
  8.         Dim i As Integer
  9.                    
  10.                
  11.         EmptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
  12.        
  13.  
  14.         ID = IDText.Text
  15.         Name = NameText.Text
  16.         Test1 = T1Text.Text
  17.         Mid = MidText.Text
  18.         Test2 = T2Text.Text
  19.         Final = FinalText.Text
  20.        
  21.         Total = Test1 + Mid + Test2 + Final
  22.         Percentage = Total / 4
  23.  
  24.                 If Percentage >= 86 Then
  25.                     Grade = "A"
  26.                 Else
  27.                     If Percentage >= 75 Then
  28.                     Grade = "B+"
  29.                 Else
  30.                 If Percentage >= 68 Then
  31.                     Grade = "B"
  32.                 Else
  33.                 If Percentage >= 60 Then
  34.                     Grade = "C"
  35.                 Else
  36.                 If Percentage >= 50 Then
  37.                     Grade = "D"
  38.                 Else
  39.                     Grade = "E"
  40.            
  41.                
  42.                 End If
  43.                 End If
  44.                 End If
  45.                 End If
  46.                 End If
  47.            
  48.                
  49.                
  50.         Flag = False
  51.         i = 2
  52.         Do While Cells(i, 1).Value <> ""
  53.             'MsgBox (Cells(i + 1, 1).Value)
  54.            
  55.             ' If the ID in row i is identical to ID From the TextBox is the form
  56.            If Cells(i, 1).Value = ID Then
  57.                 'Update THAT row in the table
  58.                Gradesheet.Cells(i, 2) = Name
  59.                 Gradesheet.Cells(i, 3) = Test1
  60.                 Gradesheet.Cells(i, 4) = Mid
  61.                 Gradesheet.Cells(i, 5) = Test2
  62.                 Gradesheet.Cells(i, 6) = Final
  63.                 Gradesheet.Cells(i, 7) = Percentage
  64.                 Gradesheet.Cells(i, 8) = Grade
  65.                 Gradesheet.Range("A:H").Columns.AutoFit
  66.  
  67.                 Flag = True
  68.             End If
  69.             i = i + 1
  70.         Loop
  71.         'If there was NO updated row
  72.        If Flag = False Then
  73.                 'Add a new row
  74.                Gradesheet.Cells(EmptyRow, 1) = ID
  75.                 Gradesheet.Cells(EmptyRow, 2) = Name
  76.                 Gradesheet.Cells(EmptyRow, 3) = Test1
  77.                 Gradesheet.Cells(EmptyRow, 4) = Mid
  78.                 Gradesheet.Cells(EmptyRow, 5) = Test2
  79.                 Gradesheet.Cells(EmptyRow, 6) = Final
  80.                 Gradesheet.Cells(EmptyRow, 7) = Percentage
  81.                 Gradesheet.Cells(EmptyRow, 8) = Grade
  82.                 Gradesheet.Range("A:H").Columns.AutoFit
  83.         End If
  84.        
  85.  
  86. End Sub
  87.  
  88. Private Sub DeleteStudent_Click()
  89.  
  90. Dim Flag As Boolean, i As Integer, ID As String
  91.         Dim Found As Boolean
  92.         Found = False
  93.        
  94.         ID = IDText.Text
  95.        
  96.         Flag = False
  97.         i = 1
  98.         Do While Cells(i, 1).Value <> ""
  99.         ' If the ID in row i is identical to ID From the TextBox is the form
  100.        If Cells(i, 1).Value = ID Then
  101.         'Modify the row with the next
  102.            Found = True
  103.             'Indicate that there EXISTS a row with the name ID
  104.        End If
  105.        
  106.         If Found = True Then
  107.             Gradesheet.Cells(i, 1) = Gradesheet.Cells(i + 1, 1)
  108.             Gradesheet.Cells(i, 2) = Gradesheet.Cells(i + 1, 2)
  109.             Gradesheet.Cells(i, 3) = Gradesheet.Cells(i + 1, 3)
  110.             Gradesheet.Cells(i, 4) = Gradesheet.Cells(i + 1, 4)
  111.             Gradesheet.Cells(i, 5) = Gradesheet.Cells(i + 1, 5)
  112.             Gradesheet.Cells(i, 6) = Gradesheet.Cells(i + 1, 6)
  113.             Gradesheet.Cells(i, 7) = Gradesheet.Cells(i + 1, 7)
  114.             Gradesheet.Cells(i, 8) = Gradesheet.Cells(i + 1, 8)
  115.         End If
  116.        
  117.         i = i + 1
  118. Loop
  119.        
  120. End Sub
  121.        
  122.  
  123.  
  124. Private Sub IDTEXT_Change()
  125.  
  126.         Dim Flag As Boolean, i As Integer, ID As String
  127.        
  128.         ID = IDText.Text
  129.        
  130.        
  131.         Flag = False
  132.         i = 2
  133.         Do While Cells(i, 1).Value <> ""
  134.         ' If the ID in row i is identical to ID From the TextBox is the form
  135.        If Cells(i, 1).Value = ID Then
  136.             'Update the OTHER text boxes
  137.            
  138.             NameText.Text = Gradesheet.Cells(i, 2)
  139.             T1Text.Text = Gradesheet.Cells(i, 3)
  140.             MidText.Text = Gradesheet.Cells(i, 4)
  141.             T2Text.Text = Gradesheet.Cells(i, 5)
  142.             FinalText.Text = Gradesheet.Cells(i, 6)
  143.  
  144.             'Indicate that there EXISTS a row with the name ID
  145.            Flag = True
  146.         End If
  147.         i = i + 1
  148.     Loop
  149.         'If there was NO updated row
  150.    If Flag = False Then
  151.             'Empty the other text boxes
  152.            NameText.Text = ""
  153.             T1Text.Text = ""
  154.             MidText.Text = ""
  155.             T2Text.Text = ""
  156.             FinalText.Text = ""
  157.         End If
  158.  
  159. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement