Advertisement
Guest User

Untitled

a guest
Aug 4th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3.         'Creating the courses when the program loads
  4.        'First courses combobox when registering
  5.        ComboBox1.Items.Add("Computing Technologies")
  6.         ComboBox1.Items.Add("Business Management")
  7.         ComboBox1.Items.Add("General Medical Practice")
  8.         ComboBox1.Text = "Select course..."
  9.         'Second combobox with courses when listing
  10.        ComboBox2.Items.Add("Computing Technologies")
  11.         ComboBox2.Items.Add("Business Management")
  12.         ComboBox2.Items.Add("General Medical Practice")
  13.         ComboBox2.Text = "Select course..."
  14.     End Sub
  15.  'Creating coruse arrays
  16.    Dim course1Array As New List(Of Student)
  17.     Dim course2Array As New List(Of Student)
  18.     Dim course3Array As New List(Of Student)
  19.  
  20.     'Variable declaration
  21.    Dim firstName As String
  22.     Dim surName As String
  23.     Dim telNumber As Integer
  24.  
  25.     'Function for registering a student to a course
  26.    Private Sub RegisterStudent(fName As String, sName As String, tNumber As Integer)
  27.         If ComboBox1.SelectedItem = "Computing Technologies" Then
  28.             course1Array.Add(New Student(firstName, surName, telNumber))
  29.             MessageBox.Show("Student added to course " + ComboBox1.SelectedItem)
  30.         End If
  31.  
  32.         If ComboBox1.SelectedItem = "Business Management" Then
  33.             course2Array.Add(New Student(firstName, surName, telNumber))
  34.             MessageBox.Show("Student added to course " + ComboBox1.SelectedItem)
  35.         End If
  36.  
  37.         If ComboBox1.SelectedItem = "General Medical Practice" Then
  38.             course3Array.Add(New Student(firstName, surName, telNumber))
  39.             MessageBox.Show("Student added to course " + ComboBox1.SelectedItem)
  40.         End If
  41.     End Sub
  42.  
  43.     'Function for searching a student in a course
  44.    Private Sub SearchStudent(tNumber As Integer)
  45.         Dim found As Boolean = False
  46.  
  47.         If ComboBox1.SelectedItem = "Computing Technologies" Then
  48.             For Each student As Student In course1Array
  49.                 If student.Number = tNumber Then
  50.                     found = True
  51.                 End If
  52.             Next
  53.  
  54.             If found = True Then
  55.                 MessageBox.Show("Student found enrolled in this course")
  56.             Else
  57.                 MessageBox.Show("Student not enrolled in this course")
  58.             End If
  59.         End If
  60.  
  61.         If ComboBox1.SelectedItem = "Business Management" Then
  62.             For Each student As Student In course2Array
  63.                 If student.Number = tNumber Then
  64.                     found = True
  65.                 End If
  66.             Next
  67.  
  68.             If found = True Then
  69.                 MessageBox.Show("Student found enrolled in this course")
  70.             Else
  71.                 MessageBox.Show("Student not enrolled in this course")
  72.             End If
  73.         End If
  74.  
  75.         If ComboBox1.SelectedItem = "General Medical Practice" Then
  76.             For Each student As Student In course3Array
  77.                 If student.Number = tNumber Then
  78.                     found = True
  79.                 End If
  80.             Next
  81.  
  82.             If found = True Then
  83.                 MessageBox.Show("Student found enrolled in this course")
  84.             Else
  85.                 MessageBox.Show("Student not enrolled in this course")
  86.             End If
  87.         End If
  88.     End Sub
  89.  
  90.     'Function for deleting a student in a course
  91.    Private Sub DeleteStudent(fname As String, sName As String, tNumber As Integer)
  92.         Dim found As Boolean = False
  93.         Dim index As Integer = 0
  94.  
  95.         If ComboBox1.SelectedItem = "Computing Technologies" Then
  96.             For Each student As Student In course1Array
  97.                 If student.Name = fname And student.LastName = sName And student.Number = tNumber Then
  98.                     found = True
  99.                     index = course1Array.IndexOf(student)
  100.                 End If
  101.             Next
  102.  
  103.             If found = True Then
  104.                 course1Array.Remove(course1Array(index))
  105.                 MessageBox.Show("Student removed from the course")
  106.             Else
  107.                 MessageBox.Show("Student not enrolled in this course")
  108.             End If
  109.         End If
  110.  
  111.         If ComboBox1.SelectedItem = "Business Management" Then
  112.             For Each student As Student In course2Array
  113.                 If student.Name = fname And student.LastName = sName And student.Number = tNumber Then
  114.                     found = True
  115.                     index = course2Array.IndexOf(student)
  116.                 End If
  117.             Next
  118.  
  119.             If found = True Then
  120.                 course2Array.Remove(course2Array(index))
  121.                 MessageBox.Show("Student removed from the course")
  122.             Else
  123.                 MessageBox.Show("Student not enrolled in this course")
  124.             End If
  125.         End If
  126.  
  127.         If ComboBox1.SelectedItem = "General Medical Practice" Then
  128.             For Each student As Student In course3Array
  129.                 If student.Name = fname And student.LastName = sName And student.Number = tNumber Then
  130.                     found = True
  131.                     index = course3Array.IndexOf(student)
  132.                 End If
  133.             Next
  134.  
  135.             If found = True Then
  136.                 course1Array.Remove(course3Array(index))
  137.                 MessageBox.Show("Student removed from the course")
  138.             Else
  139.                 MessageBox.Show("Student not enrolled in this course")
  140.             End If
  141.         End If
  142.     End Sub
  143.  
  144.     'Function for listing all students registered to a course
  145.    Private Sub ListStudents()
  146.         If ComboBox2.SelectedItem = "Computing Technologies" Then
  147.             For Each student As Student In course1Array
  148.                 ListBox1.Items.Add(student.Name + " " + student.LastName)
  149.             Next
  150.         End If
  151.  
  152.         If ComboBox2.SelectedItem = "Business Management" Then
  153.             For Each student As Student In course2Array
  154.                 ListBox1.Items.Add(student.Name + " " + student.LastName)
  155.             Next
  156.         End If
  157.  
  158.         If ComboBox2.SelectedItem = "General Medical Practice" Then
  159.             For Each student As Student In course3Array
  160.                 ListBox1.Items.Add(student.Name + " " + student.LastName)
  161.             Next
  162.         End If
  163.     End Sub
  164.   'Pressing the Register button
  165.    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  166.         firstName = TextBox1.Text
  167.         surName = TextBox2.Text
  168.         telNumber = TextBox3.Text      
  169.         RegisterStudent(firstName, surName, telNumber)
  170.        
  171.     End Sub
  172.  'Pressing the Search button
  173.    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  174.         'firstName = TextBox1.Text
  175.        'surName = TextBox2.Text
  176.        telNumber = TextBox3.Text
  177.  
  178.         SearchStudent(telNumber)
  179.     End Sub
  180.  Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  181.         firstName = TextBox1.Text
  182.         surName = TextBox2.Text
  183.         telNumber = TextBox3.Text
  184.  
  185.         DeleteStudent(firstName, surName, telNumber)
  186.     End Sub
  187.  'Pressing the List button
  188.    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  189.         ListBox1.Items.Clear()
  190.         ListStudents()
  191.     End Sub
  192. End Class
  193. 'Creating student class
  194. Public Class Student
  195.  
  196.     Private firstName As String
  197.     Private surName As String
  198.     Private telNumber As Integer
  199.  
  200.     'Constructor
  201.    Public Sub New(fName As String, sName As String, tNumber As Integer)
  202.         Me.firstName = fName
  203.         Me.surName = sName
  204.         Me.telNumber = tNumber
  205.     End Sub
  206.     'Getters and setters
  207.    Public Property Name() As String
  208.         Get
  209.             Return firstName
  210.         End Get
  211.         Set(value As String)
  212.             firstName = value
  213.         End Set
  214.     End Property
  215.     Public Property LastName() As String
  216.         Get
  217.             Return surName
  218.         End Get
  219.         Set(value As String)
  220.             surName = value
  221.         End Set
  222.     End Property
  223.     Public Property Number() As Integer
  224.         Get
  225.             Return telNumber
  226.         End Get
  227.         Set(value As Integer)
  228.             telNumber = value
  229.         End Set
  230.     End Property
  231.  
  232.  
  233. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement