Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit On
- Module Module1
- Sub Main()
- Do
- Console.Title = "Spelling Bee" 'title
- login() 'jumps to the login procedure
- Loop
- End Sub
- Sub login()
- Dim correctLogin As Boolean = False
- Dim intLevel As Integer
- Dim strUsername As String
- Do
- Console.Clear()
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Login")
- Console.ForegroundColor = ConsoleColor.White
- Console.Write("Username: ")
- strUsername = Console.ReadLine
- Console.Write("Password: ")
- Dim strPassword As String = Console.ReadLine
- Console.WriteLine() 'inputs login details
- If My.Computer.FileSystem.FileExists("C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv") Then
- 'If My.Computer.FileSystem.FileExists("\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv") Then
- Else 'if accounts database doesnt exist it creates one and creates the admin account
- FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Output)
- 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Output)
- PrintLine(1, "admin,changeme, 1")
- FileClose(1)
- End If
- FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
- 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
- 'opens the file to read from
- Dim strFullLine As String
- Do Until EOF(1)
- strFullLine = LineInput(1)
- Dim strItem() As String = Split(strFullLine, ",")
- If strItem(0) = strUsername Then
- If strItem(1) = strPassword Then
- correctLogin = True
- intLevel = strItem(2)
- Exit Do
- End If
- End If
- Loop
- FileClose(1) 'checks the login details to the database the closes file
- If correctLogin = False Then
- Console.WriteLine("Incorrect login.")
- Threading.Thread.Sleep(1000)
- End If
- Loop Until correctLogin = True
- Select Case intLevel
- Case 1
- admin()
- Case 2
- teacher(strUsername)
- Case 3, 4, 5, 6
- pupil(intLevel, strUsername)
- End Select 'sends the user to the correct account
- End Sub
- Sub admin() '***Add feature to change admin password
- Do
- Console.Clear()
- Console.Title = "Spelling Bee - Admin"
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Admin panel")
- Console.ForegroundColor = ConsoleColor.White
- Console.WriteLine("1 - Create account")
- Console.WriteLine("2 - Delete account")
- Console.WriteLine("3 - View accounts")
- Console.WriteLine("4 - Priority levels")
- Console.WriteLine("0 - Logout")
- Console.WriteLine()
- Console.Write("Enter selection: ")
- Dim bytChoice As Byte = Console.ReadLine 'make selection
- Select Case bytChoice 'takes you to the correct sub routine
- Case 1
- createAccount()
- Case 2
- deleteAccount()
- Case 3
- viewAccount()
- Case 4
- priorityLevels()
- Case 0
- Exit Sub
- Case Else
- Console.WriteLine()
- Console.WriteLine("Input invalid.") 'validation
- Threading.Thread.Sleep(1000)
- End Select
- Loop
- End Sub
- Sub createAccount() '***Add a function to return to the menu
- Dim again As Boolean = True 'swtich to jump out the again loop
- Dim strFullLine As String
- Do
- Do
- Console.Clear()
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Admin panel - Create account")
- Console.ForegroundColor = ConsoleColor.White
- Console.Write("Username: ")
- Dim strUsername As String = Console.ReadLine
- Console.Write("Password: ")
- Dim strPassword As String = Console.ReadLine
- Console.Write("Level: ")
- Dim intLevel As String = Console.ReadLine
- strFullLine = strUsername + "," + strPassword + "," + intLevel
- FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
- 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
- Dim strCheckLine As String = ""
- Do Until EOF(1)
- strCheckLine = LineInput(1)
- If strCheckLine = strFullLine Then
- Exit Do
- End If
- Loop
- FileClose(1) 'checks if the account being created already exists
- If strCheckLine = strFullLine Then
- Console.WriteLine()
- Console.WriteLine("This account already exists.")
- Threading.Thread.Sleep(1000)
- Else
- Exit Do
- End If
- Loop '
- FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Append)
- 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Append)
- PrintLine(1, strFullLine)
- FileClose(1) 'stores account
- Dim intCount As Integer
- intCount += 1 'a count to tell the user how many accounts have been created
- Do
- Console.WriteLine()
- Console.Write("Would you like to create another account?(Y/N)")
- Dim chrChoice As Char = Console.ReadLine
- Select Case chrChoice
- Case "Y", "y"
- Exit Do
- Case "N", "n"
- again = False
- Exit Do
- Case Else
- Console.WriteLine("Invalid input.")
- End Select 'asks if you want to enter another account
- Loop
- If again = False Then
- Console.Write("Saving ")
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.Write(intCount)
- Console.ForegroundColor = ConsoleColor.White
- Console.WriteLine(" accounts to system.")
- Console.WriteLine()
- Threading.Thread.Sleep(2000)
- Exit Do 'displays the amount of accounts created
- End If
- Loop
- End Sub
- Sub deleteAccount() '***Add a function to return to the menu
- Dim found As Boolean = False
- Dim intCount As Integer = 0
- Dim strCheckLine(1000) As String
- Do
- Console.Clear()
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Admin panel - Delete account")
- Console.ForegroundColor = ConsoleColor.White
- Console.Write("Username: ")
- Dim strUsername As String = Console.ReadLine
- Console.Write("Password: ")
- Dim strPassword As String = Console.ReadLine
- Console.Write("Level: ")
- Dim intLevel As String = Console.ReadLine
- Dim strFullLine As String = ""
- strFullLine = strUsername + "," + strPassword + "," + intLevel 'enter the account to delete and stores all values as one string
- FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
- 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
- Do Until EOF(1)
- intCount += 1
- strCheckLine(intCount) = LineInput(1)
- Loop
- FileClose(1) 'loads all accounts from csv into an array
- Dim intCount2 As Integer = 0
- For intCheck As Integer = 1 To intCount
- intCount2 += 1
- If strFullLine = strCheckLine(intCount2) Then
- strCheckLine(intCount2) = Nothing
- found = True
- Exit For
- End If
- Next 'searches for account
- If found = True Then
- Console.WriteLine()
- Console.WriteLine("Deleting account...")
- Threading.Thread.Sleep(1000)
- Exit Do
- Else
- Console.WriteLine()
- Console.WriteLine("User not found.")
- Threading.Thread.Sleep(1000)
- End If 'if the user was deleted it jumps out the Do Loop else it says User not found and reloops
- Loop
- For intCheck2 As Integer = 1 To intCount
- If strCheckLine(intCheck2) = Nothing Then
- If strCheckLine(intCheck2 + 1) <> Nothing Then
- strCheckLine(intCheck2) = strCheckLine(intCheck2 + 1)
- strCheckLine(intCheck2 + 1) = Nothing
- End If
- End If
- Next 'sorts the new data removing the blank gap in the csv
- FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Output)
- 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Output)
- For intSave As Integer = 1 To intCount
- PrintLine(1, strCheckLine(intSave))
- Next
- FileClose(1) 'saves over the previous file excluding the deleted accounts
- End Sub
- Sub viewAccount()
- Console.Clear()
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Admin panel - View accounts")
- Console.ForegroundColor = ConsoleColor.White
- Console.Write("Enter level you wish to view: ")
- Dim intLevel As Integer = Console.ReadLine
- Console.WriteLine()
- If intLevel < 1 Or intLevel > 6 Then
- Console.WriteLine("Invalid input.")
- Console.WriteLine()
- End If 'validation
- FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
- 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
- Dim strFullLine As String = ""
- Dim check As Boolean = False
- Do Until EOF(1)
- strFullLine = LineInput(1)
- Dim strItem() As String = Split(strFullLine, ",")
- If strItem(2) = intLevel Then
- Console.WriteLine(strFullLine)
- check = True
- End If
- Loop 'allows the user to view the accounts of the selected level
- If check = False Then
- Console.WriteLine("No accounts found.")
- End If
- FileClose(1)
- Console.WriteLine()
- Console.WriteLine("Press enter to return...")
- Console.ReadLine()
- End Sub
- Sub priorityLevels()
- Console.Clear()
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Admin panel - Priority levels")
- Console.ForegroundColor = ConsoleColor.White
- Console.WriteLine("1: Admin")
- Console.WriteLine("2: Teacher")
- Console.WriteLine("3: Year 3")
- Console.WriteLine("4: Year 4")
- Console.WriteLine("5: Year 5")
- Console.WriteLine("6: Year 6")
- Console.WriteLine()
- Console.WriteLine("Press enter to return...")
- Console.ReadLine() 'displays what each priority level is for then takes you back to the admin panel
- End Sub
- Sub teacher(ByVal strUsername As String)
- Do
- Console.Clear()
- Console.Title = "Spelling Bee - " + strUsername
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Teacher panel")
- Console.ForegroundColor = ConsoleColor.White
- Console.WriteLine("1 - Add spellings")
- Console.WriteLine("2 - View past spellings")
- Console.WriteLine("3 - View test results")
- Console.WriteLine("0 - Logout")
- Console.Write("Enter selection: ")
- Dim intChoice As Integer = Console.ReadLine
- Select Case intChoice
- Case 1
- addSpellings()
- Case 2
- pastSpellings()
- Case 3
- testResults()
- Case 0
- Exit Sub
- Case Else
- Console.WriteLine()
- Console.WriteLine("Invalid input.")
- Threading.Thread.Sleep(1000)
- End Select
- Loop
- End Sub
- Sub addSpellings()
- Console.Clear()
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Teacher panel - Add spellings")
- Console.ForegroundColor = ConsoleColor.White
- End Sub
- Sub pastSpellings()
- Console.Clear()
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Teacher panel - Past spellings")
- Console.ForegroundColor = ConsoleColor.White
- End Sub
- Sub testResults()
- Console.Clear()
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Teacher panel - Test results")
- Console.ForegroundColor = ConsoleColor.White
- End Sub
- Sub pupil(ByVal intLevel As Integer, strUsername As String)
- Console.Clear()
- Console.Title = "Spelling Bee - " 'add pupils user here
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("Spelling test")
- Console.ForegroundColor = ConsoleColor.White
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement