Task 1 Task 1.1 Dim StudName, StudEmail, DOB As String Dim StudentLine As String 'Dim Index As Integer // array index Dim StudentDetail(3) As String Task 1.2 Dim DeleteArray As Integer Task 1.3 Dim Index, i As Integer Dim SearchName As String Dim Name As String Dim Length As Integer Dim Count, Pos1, Pos2 As Integer Dim FoundName As Boolean Dim Email As String Task 1.4 Dim year As String Dim Month As String Dim SearchMonth As String Task 1.5 Dim AddMoreDetail(3, 5) As String 'Dim Index As Integer Task 1.6 Dim SearchStudName As String '.........................Task 1.1................................ For Index = 1 To 3 Console.Write("Enter student name: ") StudName = Console.ReadLine() Console.Write("Enter student email: ") StudEmail = Console.ReadLine() Console.Write("Enter student date of birth: ") DOB = Console.ReadLine() StudentLine = (StudName & "*" & StudEmail & "*" & DOB) StudentDetail(Index) = StudentLine Console.WriteLine() Next Console.WriteLine() .........................Task 1.2................................ Console.Write("Enter array number to delete: ") DeleteArray = Console.ReadLine() For Index = 1 To 3 If DeleteArray = Index Then StudentDetail(Index) = "" End If If StudentDetail(Index) <> "" Then Console.WriteLine(StudentDetail(Index)) End If Next .........................Task 1.3................................ Console.WriteLine("Enter search name: ") SearchName = Console.ReadLine() Index = 1 FoundName = False Do Count = 0 Length = Len(StudentDetail(Index)) For i = 1 To Length If Mid(StudentDetail(Index), i, 1) = "*" Then Count = Count + 1 If Count = 1 Then Pos1 = i Else ''Used ELSE CASE if not using fixed DOB If Count = 2 Then Pos2 = i End If End If End If Next Name = Left(StudentDetail(Index), Pos1 - 1) If SearchName = Name Then FoundName = True 'Email = Mid(StudentDetail(Index), Pos1 + 1, Length - Pos1 - 10 ) 'fixed DOB Email = Mid(StudentDetail(Index), Pos1 + 1, Pos2 - 1 - Pos1) 'DOB not fixed Console.WriteLine(Email) End If Index = Index + 1 Loop Until (Index > 3 Or FoundName = True) '.........................Task 1.4................................ Console.WriteLine("Enter search month: ") SearchMonth = Console.ReadLine() For Index = 1 To 3 year = Right(StudentDetail(Index), 9) Month = Mid(year, 3, 3) If SearchMonth = Month Then Console.WriteLine(StudentDetail(Index)) End If Next '.........................Task 1.5................................ Index = 1 Do Count = 0 Length = Len(StudentDetail(Index)) For i = 1 To Length If Mid(StudentDetail(Index), i, 1) = "*" Then Count = Count + 1 If Count = 1 Then Pos1 = i Else 'Used ELSE CASE if not using fixed DOB If Count = 2 Then Pos2 = i End If End If End If Next AddMoreDetail(Index, 1) = Left(StudentDetail(Index), Pos1 - 1) 'Student name AddMoreDetail(Index, 2) = Mid(StudentDetail(Index), Pos1 + 1, Pos2 - 1 - Pos1) 'Student email AddMoreDetail(Index, 3) = Right(StudentDetail(Index), 9) Console.WriteLine("Enter student Id: ") AddMoreDetail(Index, 4) = Console.ReadLine() Console.WriteLine("Enter tutor Id: ") AddMoreDetail(Index, 5) = Console.ReadLine() Index = Index + 1 Loop Until Index > 3 'Display Array Console.WriteLine("Student_Name Email_Address Date_Of_Birth StudentID TutorID") For Index = 1 To 3 Console.WriteLine(AddMoreDetail(Index, 1) & "" & AddMoreDetail(Index, 2) & "" & AddMoreDetail(Index, 3) & "" & AddMoreDetail(Index, 4) & "" & AddMoreDetail(Index, 5)) Next '.........................Task 1.6................................ 'Example 1: Search name to display email Console.Write("Enter search name: ") SearchStudName = Console.ReadLine() For Index = 1 To 3 If AddMoreDetail(Index, 1) = SearchStudName Then Console.WriteLine(AddMoreDetail(Index, 2)) End If Next Console.ReadKey() End Sub End Module Task 2 'Task 2.1 Sub EnterDetail() Dim StudentId, Email, DOB, text As String Dim Index As Integer Dim validId, ValidDOB As Boolean FileOpen(1, "Stud.txt", OpenMode.Append) For Index = 1 To 3 Do Console.Write("Enter student ID: ") StudentId = Console.ReadLine() validId = ValidateStudentId(StudentId) Loop Until (validId = True) Console.Write("Enter student email: ") Email = Console.ReadLine() Do Console.Write("Enter DOB: ") DOB = Console.ReadLine() ValidDOB = ValidateStudentDOB(DOB) Loop Until (ValidDOB = True) text = (StudentId & Email & DOB) PrintLine(1, text) Next FileClose(1) End Sub 'Task 2.2 Sub SearchStudId() FileOpen(1, "Stud.txt", OpenMode.Input) Dim studline, searchId As String Dim foundId As Boolean Console.Write("Enter search studentId: ") searchId = Console.ReadLine() foundId = False While Not EOF(1) studline = LineInput(1) If Left(studline, 6) = searchId Then foundId = True Console.WriteLine(Mid(studline, 7, (Len(studline) – 6 - 6))) End If End While If foundId = False Then Console.WriteLine("StudentId not found") End If FileClose(1) End Sub 'Task 2.3 Sub SearchStudIdChar() FileOpen(1, "Stud.txt", OpenMode.Input) Dim studline, searchIdChar, character As String Dim sId, sEmail, sDOB As String Console.Write("Enter 2 character of studentId: ") searchIdChar = Console.ReadLine() While Not EOF(1) studline = LineInput(1) character = Left(studline, 2) If searchIdChar = character Then sId = Left(studline, 6) Console.WriteLine(sId) sEmail = (Mid(studline, 7, (Len(studline) - 6 - 6))) Console.WriteLine(sEmail) sDOB = Right(studline, 6) Console.WriteLine(sDOB) End If End While FileClose(1) End Sub 'Task 2.5 Function ValidateStudentId(ByVal studId As String) As Boolean If ((Len(studId) = 6) And (Left(studId, 2) >= "AA" And Left(studId, 2) <= "ZZ") And (Right(studId, 4) <= "9999")) Then Return True Else Return False End If End Function 'Task 2.5 Function ValidateStudentDOB(ByVal studDOB As String) As Boolean If ((Len(studDOB) = 6) And (Left(studDOB, 2) >= "01" And Left(studDOB, 2) <= "31") And (Mid(studDOB, 3, 2) >= "01" And Mid(studDOB, 3, 2) <= "12") And (Right(studDOB, 2) > "00")) Then Return True Else Return False End If End Function …………………………………………………………………………………………………………………………………………………………………………………… Sub main() Dim choice As Integer Do Console.WriteLine("Enter choice: ") choice = Console.ReadLine() Loop Until (choice >= 1 Or choice <= 4) Select Case choice Case 1 Call EnterDetail() Case 2 Call SearchStudId() Case 3 Call SearchStudIdChar() Case 4 Console.WriteLine("Exit program") End Select Console.ReadKey() End Sub