Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Structure teacher_login
- Dim username As String
- Dim password As String
- End Structure
- Structure student_login
- Dim username As String
- Dim password As String
- Dim name As String
- Dim year As String 'structure for seperate student + teacher logins
- Dim test_status As String
- End Structure
- Dim students(10) As student_login
- Dim teachers(10) As teacher_login 'assigns name to structure
- Dim counter_S As Integer = 0
- Dim counter_T As Integer = 0 ' need to make global as refereced in both login subs
- Dim week As Integer
- Dim words(9) As String
- Dim definitions(9) As String
- Dim login_path As String = "D:\Downloads\Spelling Be\logins.csv"
- Sub Main()
- login_file_scrape()
- login()
- End Sub
- Sub login_file_scrape()
- FileOpen(1, login_path, OpenMode.Input)
- Do Until EOF(1)
- Dim line As String = LineInput(1)
- Dim temp() As String = Split(line, ",") 'extracts the line and splits it with the commas
- If temp(2) = "S" Then
- students(counter_S).username = temp(0)
- students(counter_S).password = temp(1)
- students(counter_S).name = temp(3)
- students(counter_S).year = temp(4)
- students(counter_S).test_status = temp(5) 'whether the student has completed the test for the week.
- counter_S += 1
- Else
- teachers(counter_T).username = temp(0)
- teachers(counter_T).password = temp(1)
- counter_T += 1
- End If
- 'if status field is S then store in student record
- 'else store in teacher record
- Loop
- 'counters used to track how many students and teachers so the corresponding arrays
- 'to be created will have an upper limit
- FileClose(1)
- End Sub
- Sub login()
- Console.Clear()
- Console.WriteLine("Username:")
- Dim U_name As String = Console.ReadLine
- Console.WriteLine("Password:")
- Dim P_word As String = Console.ReadLine
- For i = 0 To counter_S - 1
- If U_name.ToLower = students(i).username.ToLower And P_word = students(i).password Then
- student_menu(students(i).year, students(i).name)
- 'passes the year and name of the student
- End If
- Next
- 'check for student login
- For i = 0 To counter_T - 1
- If U_name.ToLower = teachers(i).username.ToLower And P_word = teachers(i).password Then
- teacher_menu()
- End If
- 'if not loops back to the login screen
- Next
- 'only reaches the end if incorrect login
- Console.WriteLine("Wrong Username or Password")
- Console.ReadLine()
- login() 'if it reaches the bottom then we know it's not a correct U and P
- End Sub
- Sub teacher_menu()
- Console.Clear()
- Console.WriteLine("teacher menu")
- Console.WriteLine("1 - Enter new words")
- Console.WriteLine("2 - See Progress")
- Console.WriteLine("3 - Increment Week")
- Console.WriteLine("4 - logout")
- Dim action As Integer = Console.ReadLine
- If action = 1 Then
- new_words()
- ElseIf action = 2 Then
- progress_tracker()
- ElseIf action = 3 Then
- score_check(week_tracker())
- week_tracker()
- reset_test_status()
- ElseIf action = 4 Then
- login()
- Else
- Console.WriteLine("invalid input")
- Console.ReadLine()
- teacher_menu()
- End If
- End Sub
- Function week_tracker()
- Dim week_filepath As String = "D:\Downloads\Spelling Be\week.csv"
- week = System.IO.File.ReadAllText(week_filepath)
- 'gets week value from file
- System.IO.File.WriteAllText(week_filepath, week + 1)
- 'increment week in file
- Console.WriteLine("Week Successfully Incremented now at week:" & (week + 1).ToString)
- Console.ReadLine()
- 'success message and loop back to menu
- Return week
- End Function
- Sub reset_test_status()
- Dim login_filepath As String = "D:\Downloads\Spelling Be\logins.csv"
- Dim lines() As String = System.IO.File.ReadAllLines(login_filepath)
- For i = 0 To lines.Length - 1
- Dim temp() As String = Split(lines(i), ",")
- If temp(2) = "S" Then
- 'check if line belongs to student, if so take action
- lines(i) = lines(i).TrimEnd()
- 'removes spaces from the end
- If lines(i).EndsWith(True) Then
- lines(i) = lines(i).Substring(0, lines(i).Length - 4) & False
- End If
- 'trims end and replaces with false, no action needed if end already false
- End If
- System.IO.File.WriteAllLines(login_filepath, lines)
- 'rewrite with corrections
- Next
- teacher_menu()
- End Sub
- Sub score_check(ByVal week) 'checks if student has done the test for the week if not set their score for the week as 0
- Dim score_filepath As String = "D:\Downloads\Spelling Be\scores.csv"
- Dim lines() As String = System.IO.File.ReadAllLines(score_filepath)
- For i = 0 To lines.Length - 1
- Dim temp() As String = Split(lines(i), ",")
- If temp.Length = week Then
- lines(i) = lines(i) & ",0"
- End If
- 'the further along the week is the more score entries there should be
- 'by comparing the amount of entries we know if the student has completed the test for the week.
- 'if not edit their line so that the score is 0
- Next
- System.IO.File.WriteAllLines(score_filepath, lines)
- 'rewrite file with corrects (if any)
- End Sub
- Sub new_words()
- Console.WriteLine("What year to edit words for? 3,4,5,6")
- Dim year As Integer = Console.ReadLine
- 'gets year to edit
- Dim year_filepath As String = "D:\Downloads\Spelling Be\year" & year.ToString & "_words.csv"
- Dim lines(9) As String
- 'limited to 10 lines (10 words + definitions)
- For i = 0 To 9
- Console.Write("Enter the word: ")
- Dim words As String = Console.ReadLine
- Console.Write("Enter the corresponding definition: ")
- Dim definitions As String = Console.ReadLine
- lines(i) = "" & words.ToString & "," & definitions & ""
- 'prompts for word and definition and write to file seperated by ","
- Next
- System.IO.File.WriteAllLines(year_filepath, lines)
- 'update the file
- Console.WriteLine("New words successfully input!")
- Console.ReadLine()
- teacher_menu()
- 'success messagen, loops back to menu
- End Sub
- Sub progress_tracker()
- Dim score_filepath As String = "D:\Downloads\Spelling Be\scores.csv"
- Dim lines() As String = System.IO.File.ReadAllLines(score_filepath)
- Console.Write("Name")
- For i = 1 To 6
- Console.Write(" Week {0}", i)
- Next
- Console.WriteLine("")
- For i = 0 To lines.Length - 1
- Dim temp() As String = Split(lines(i), ",")
- Console.WriteLine("" & vbCr & "" & temp(0) & "")
- For k = 1 To temp.Length - 1
- Console.Write(" " & temp(k) & "")
- Next
- Next
- Console.ReadLine()
- End Sub
- Sub student_menu(ByVal student_year, ByVal student_name)
- Console.Clear()
- Dim words_definitons(9, 2) As String
- words_definitons = get_words_definitions(student_year, words_definitons)
- Console.WriteLine("Student Menu")
- Console.WriteLine("1 - Take Test")
- Console.WriteLine("2 - Log out")
- Dim choice As Integer = Console.ReadLine
- Select Case choice
- Case 1
- test_availibility(student_name) 'checks if students have completed the test for the week
- Dim score As Integer = spelling_bee(words_definitons)
- 'student takes test and returns the mark
- save_score(score, student_name)
- Case 2
- login()
- Case Else
- Console.WriteLine("Input not valid, press enter to re-enter.")
- Console.ReadLine()
- student_menu(student_year, student_name)
- End Select
- End Sub
- Function get_words_definitions(ByVal student_year, ByRef words_definitons)
- Dim words_filepath As String = "D:\Downloads\Spelling Be\year" & student_year & "_words.csv"
- Dim lines() As String = System.IO.File.ReadAllLines(words_filepath)
- 'reads word file and seperates lines into array
- For i = 0 To 9
- Dim temp() As String = Split(lines(i), ",")
- words_definitons(i, 1) = temp(0)
- words_definitons(i, 2) = temp(1)
- 'split array and assign word and definition
- Next
- Return words_definitons
- 'return populated array
- End Function
- Sub test_availibility(ByVal student_name) 'checks if the student has completed the test for the current week
- For i = 0 To counter_S - 1
- If student_name = students(i).name Then
- 'finds the line the student is on and checks if the test has been completed for the week.
- If students(i).test_status = True Then
- Console.WriteLine("You have already done the test for this week, wait until new words are set by the teacher.")
- Console.ReadLine()
- student_menu(3, student_name)
- 'if the student has comleted the test we return back to the student menu
- 'our given parameters are arbitrary as the students will not take the test, the parameters need only to not crash the program.
- 'their only availible action in the menu is to log out
- Else
- Dim lines() As String = System.IO.File.ReadAllLines("D:\Downloads\Spelling Be\logins.csv")
- For k = 0 To lines.Length - 1
- Dim temp() As String = Split(lines(k), ",")
- If student_name = temp(3) Then
- lines(k) = "" & temp(0) & "," & temp(1) & "," & temp(2) & "," & temp(3) & "," & temp(4) & "," & True & ""
- Exit For
- End If
- 'if the name matches then we edit the final field in the string to True
- Next
- System.IO.File.WriteAllLines("D:\Downloads\Spelling Be\logins.csv", lines)
- 'rewrite file with changes.
- End If
- End If
- Next
- End Sub
- Sub save_score(ByVal score, ByVal student_name)
- Dim lines() As String = IO.File.ReadAllLines("D:\Downloads\Spelling Be\scores.csv")
- 'splits text file by line sorted into 'lines' array
- Dim written As Boolean
- Console.WriteLine(counter_S)
- For i = 0 To lines.Length - 1
- Dim temp() As String = Split(lines(i), ",")
- If temp(0) = student_name Then
- 'if student is in file, append score to the line the student was found on and rewrite file with the addition.
- lines(i) = lines(i) & "," & score & ""
- System.IO.File.WriteAllLines("D:\Downloads\Spelling Be\scores.csv", lines)
- 'rewrites the lines to the file with the added score
- written = True
- Exit For
- End If
- Next
- If written <> True Then
- System.IO.File.AppendAllText("D:\Downloads\Spelling Be\scores.csv", vbCrLf + "" & student_name & "," & score & "")
- End If
- 'if no previous entry we append to end of file on a new line
- End Sub
- Function spelling_bee(ByVal words_definitions)
- Dim marks As Integer = 0
- Dim no_error As Integer
- For i = 0 To 9
- Console.WriteLine(words_definitions(i, 2))
- Console.WriteLine("Enter the matching word")
- Dim ans As String = Console.ReadLine
- If ans.ToLower.ToString = words_definitions(i, 1).ToString.ToLower Then
- Console.WriteLine("CORRECT")
- marks += 2
- ElseIf ans.Length - words_definitions(i, 1).Length < -1 Or ans.Length - words_definitions(i, 1).Length > 1 Then
- Console.WriteLine("Major error")
- Else
- Dim ansArray() As Char = ans.ToCharArray
- Dim wordsArray() As Char = words_definitions(i, 1).ToCharArray
- 'before this we check if they are the same, or 2 characters off
- 'if it reaches this if statement than we know the word is either
- 'one character too big/small or the same length
- If ansArray.Length > wordsArray.Length Then
- For j = 0 To wordsArray.Length - 1
- If wordsArray(j).ToString.Contains(ansArray(j)) = False Then
- no_error += 1
- End If
- Next
- If ansArray.Length - wordsArray.Length <> 0 Then
- no_error += 1
- End If
- 'if the input answer is longer by 1 we run it correct word amount of times to prevent calling
- 'an index too high on the word array since the input array is bigger
- ElseIf wordsArray.Length > ansArray.Length Then
- For j = 0 To ansArray.Length - 1
- If wordsArray(j).ToString.Contains(ansArray(j)) = False Then
- no_error += 1
- End If
- Next
- If ansArray.Length - wordsArray.Length <> 0 Then
- no_error += 1
- End If
- 'if the correct word is longer by 1 we run it answer amount of time for the same reasons
- Else
- For j = 0 To wordsArray.Length - 1
- If wordsArray(j).ToString.Contains(ansArray(j)) = False Then
- no_error += 1
- End If
- Next
- 'if they are the same length
- End If
- End If
- If no_error = 1 Then
- marks += 1
- Console.WriteLine("minor error")
- ElseIf no_error > 1 Then
- Console.WriteLine("major error")
- 'if only 1 error than its a minor error, if this statement isnt true then
- 'theres at least 2 errors(major) and we don't add any marks.
- End If
- no_error = 0
- Next
- Console.WriteLine("total marks was: " & marks)
- Console.ReadLine()
- Return marks
- End Function
- End Module
Add Comment
Please, Sign In to add comment