Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports System.Console
- Module Module1
- Dim usercohice As String
- Dim addfile As String = "N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEM\bin"
- Sub Main()
- Dim username2 As String
- Dim password As String
- Dim filename As String = "N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEMS FILES\DebugLogin_Details_Username.txt"
- Dim filename2 As String = "N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEMS FILES\DebugLogin_Details_Password.txt"
- Dim fileusername As String
- Dim filepassword As String
- Dim admin_login As String
- 'The filename variable stores the name that the program wants to access
- 'This lets vb know the directory that the file should be found in. it also creates a file if
- 'one with the following name doesn’t already exist
- FileOpen(1, filename, OpenMode.Input)
- fileusername = (LineInput(1))
- FileOpen(2, filename2, OpenMode.Input)
- filepassword = (LineInput(2))
- 'once the file is found fileopen will open the file and openmode.input will allow us to change whats in the file
- WriteLine("Welcome to the voting system")
- WriteLine("To vote you must login") 'introduction code
- WriteLine("As an admin you can Add a new character and calculate votes")
- WriteLine("Normal login menu will only contain vote for a character option")
- WriteLine("Would you like to log on as an ADMIN")
- ForegroundColor = ConsoleColor.Green
- WriteLine("1) Yes")
- ForegroundColor = ConsoleColor.Red
- WriteLine("2) No")
- admin_login = ReadLine()
- If admin_login = "Yes" Or admin_login = "yes" Then
- WriteLine("Switching to admin login now")
- adminLogin()
- ElseIf admin_login = "No" Or admin_login = "no" Then
- WriteLine("Staying on normal login")
- ReadLine()
- Clear()
- End If
- WriteLine("please enter your username")
- username2 = ReadLine()
- While username2 <> fileusername ' a while loop to make sure the user enters the correct username
- WriteLine("Incorrect username Please try again")
- username2 = ReadLine() 'user will be stuck in this loop until they enter correct username
- End While
- FileClose(1)
- WriteLine("please enter your password")
- password = ReadLine()
- While password <> filepassword
- ' a while loop to make sure the user enters the correct password
- WriteLine("Incorrect password please try again")
- password = ReadLine() 'like above the user will be stuck in the loop until they enter correct password
- End While
- WriteLine("Login Successful!")
- FileClose(2) 'outputs when the user is sucessful with both password and username
- mainmenu(username2) 'first sub to take user to the main menu
- End Sub
- Sub mainmenu(ByVal username2)
- Dim choice As Integer
- Clear()
- WriteLine("Main Menu:")
- WriteLine("1. vote for a character")
- WriteLine("2. add a new character")
- WriteLine("3. calculate final vote")
- WriteLine(" Please select an option from above")
- choice = ReadLine()
- If choice = 1 Then
- WriteLine("You chose vote for a character option")
- vote(username2)
- ElseIf choice = 2 Then
- WriteLine("You chose add a new character")
- add(username2)
- ElseIf choice = 3 Then
- WriteLine("You chose calculate final vote option")
- calculate()
- End If
- While choice <> "1" Or choice <> "2" Or choice <> "3"
- WriteLine("Invalid input try again")
- choice = ReadLine()
- End While
- End Sub
- Sub vote(ByVal username2)
- Dim filepath2 As String = "N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEMS FILES\index.txt"
- Dim filepath As String = "N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEMS FILES\DebugAdd_Character"
- Dim lineCount As Integer
- lineCount = File.ReadAllLines("N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEMS FILES\index.txt").Length
- lineCount = (lineCount / 2) - 1
- Dim index(lineCount, 1)
- Dim choice As String
- FileOpen(1, filepath2, OpenMode.Input)
- WriteLine("Characters available")
- For count = 0 To lineCount
- index(count, 1) = LineInput(1)
- PrintLine(1, index(count, 0))
- WriteLine()
- Next
- WriteLine("Who would you like to vote for")
- choice = ReadLine()
- For count = 0 To lineCount / 2 - 1
- If choice = index(count, 1) Then
- WriteLine("Character found getting data...")
- Console.Beep()
- FileOpen(2, index(count, 0), OpenMode.Input)
- WriteLine("You have voted for" & index(count, 0))
- ReadLine()
- PrintLine(2, username2)
- FileClose(2)
- FileClose(1)
- mainmenu(username2)
- ElseIf count = lineCount / 2 - 1 Then
- End If
- Next
- mainmenu(username2)
- End Sub
- Sub add(ByVal username2)
- Dim userchoice As String
- Dim addfile As String = "N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEMS FILES\DebugAdd_Character.txt"
- FileOpen(1, addfile, OpenMode.Append)
- ReadLine()
- WriteLine("Please enter the Full name of the character you want to add")
- WriteLine("Please note that whatever you enter will be submitted as a character to vote for")
- userchoice = ReadLine()
- While userchoice <> "stop"
- PrintLine(1, userchoice)
- WriteLine("Please enter another character or type stop to finish")
- userchoice = ReadLine()
- End While
- FileClose(1)
- mainmenu(username2)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement