Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports System.Console
- Module Module1
- Sub Main()
- Dim repeat As Boolean
- Dim username As String
- Dim password As String
- Dim accounts(8, 1) As String
- Dim userver As Boolean = False
- Dim filepath As String = "N:\voting assesment 2\storage.txt"
- Dim length As Integer = File.ReadAllLines(filepath).Length ' stores length of a file
- Dim lineCount = File.ReadAllLines(filepath).Length ' count how many lines a file has
- FileOpen(1, filepath, OpenMode.Input)
- For count = 0 To lineCount / 2 - 1
- accounts(count, 0) = LineInput(1)
- accounts(count, 1) = LineInput(1)
- Next
- WriteLine("usernames")
- For count = 0 To lineCount / 2 - 1
- WriteLine(accounts(count, 0))
- Next
- WriteLine("passwords")
- For count = 0 To lineCount / 2 - 1
- WriteLine(accounts(count, 1))
- Next
- username:
- WriteLine("Please enter your username")
- username = ReadLine()
- For count = 0 To 8
- If username = accounts(count, 0) Then
- WriteLine("username found")
- userver = True
- Do
- WriteLine("please enter your password")
- password = ReadLine()
- If password = accounts(count, 1) Then
- WriteLine("password accepted")
- repeat = False
- FileClose(1)
- menu(username)
- Else
- WriteLine("password declined")
- repeat = True
- End If
- Loop Until repeat = False
- End If
- Next
- If userver = False Then
- Console.WriteLine("username not found please re-enter")
- GoTo username
- End If
- ReadLine()
- End Sub
- Sub menu(ByVal username)
- WriteLine("Welcome " & username)
- Dim choice As String
- WriteLine("1.Choose your vote")
- WriteLine("2. Add a new character")
- WriteLine("3.Add up total votes")
- choice = Console.ReadLine()
- If choice = 1 Then
- vote(username)
- ElseIf choice = 2 Then
- addvote()
- ElseIf choice = 3 Then
- checkvote(username)
- ElseIf choice = 4 Then
- dance()
- Else : WriteLine("Please re-enter your chice")
- End If
- End Sub
- Sub dance()
- Do
- WriteLine(" \*_* ")
- WriteLine(" ( (>") ' dance guy 1
- WriteLine(" / \ ")
- Beep()
- Beep()
- Beep()
- Beep()
- Clear()
- WriteLine(" @_@/ ")
- WriteLine(" <) ) ") 'dance guy 2
- WriteLine(" / \ ")
- Beep()
- Beep()
- Beep()
- Clear()
- Loop
- End Sub
- Sub vote(ByVal username)
- Dim filepath2 As String = "N:\voting assesment 2\Index.txt"
- Dim lineCount2 = File.ReadAllLines(filepath2).Length
- Dim index(lineCount2 / 2 - 1, 1)
- Dim choice As String
- FileOpen(1, filepath2, OpenMode.Input)
- WriteLine("Hello " & username & ". Welcome to voting, here you can cast your vote on whoever is available")
- WriteLine("available characters")
- For count = 0 To lineCount2 / 2 - 1
- index(count, 0) = LineInput(1)
- index(count, 1) = LineInput(1)
- WriteLine(index(count, 0))
- WriteLine()
- Next
- WriteLine("Who would you like to vote for? ^")
- choice = ReadLine()
- For count = 0 To lineCount2 / 2 - 1
- If choice = index(count, 0) Then
- WriteLine("Character found. Getting data...")
- FileOpen(2, index(count, 1), OpenMode.Append)
- WriteLine("You have voted for" & index(count, 0))
- ReadLine()
- PrintLine(2, username)
- FileClose(2)
- FileClose(1)
- menu(username)
- ElseIf count = lineCount2 / 2 - 1 Then
- End If
- Next
- End Sub
- Sub addvote()
- Dim chara As String
- Dim charver As String
- Dim filepath2 As String = "N:\voting assesment 2\Index.txt"
- Dim lineCount = File.ReadAllLines(filepath2).Length
- FileOpen(1, filepath2, OpenMode.Append)
- WriteLine("Welcome to add vote")
- name:
- WriteLine("Please enter your characters name.")
- chara = ReadLine()
- WriteLine("Please verify your characters name.")
- charver = ReadLine()
- If charver = chara Then
- WriteLine("Characters match! Exporting data.")
- Dim path As String = "C:\voting assesment 2\Characters\" & chara & ".txt"
- WriteLine("Character file created @" & path)
- File.Create("C:\voting assesment 2\Characters\" & chara & ".txt")
- PrintLine(1, chara)
- PrintLine(1, path)
- ElseIf charver <> chara Then
- Clear()
- WriteLine("Names did not match please try again")
- GoTo name
- End If
- End Sub
- Sub checkvote(ByVal username)
- Clear()
- Dim filepath2 As String = "N:\voting assesment 2\Index.txt"
- Dim lineCount2 = File.ReadAllLines(filepath2).Length
- Dim index(lineCount2 / 2 - 1, 1)
- Dim choice As String
- FileOpen(1, filepath2, OpenMode.Input)
- WriteLine("Hello " & username & ". Welcome to total votes here you can check each character and see how many votes they have and who has voted")
- For count = 0 To lineCount2 / 2 - 1
- index(count, 0) = LineInput(1)
- index(count, 1) = LineInput(1)
- Next
- choice:
- WriteLine("available characters")
- For count = 0 To lineCount2 / 2 - 1
- WriteLine(index(count, 0))
- WriteLine()
- Next
- WriteLine("please choose a character to display extra data")
- choice = ReadLine()
- For count = 0 To lineCount2 / 2 - 1
- If choice = index(count, 0) Then
- Dim linecount As String = File.ReadAllLines(index(count, 1)).Length
- WriteLine("Character found. Loading")
- For count2 = 0 To 5
- Write(".")
- Beep()
- Next
- WriteLine(" Done")
- Beep()
- Beep()
- Beep()
- Clear()
- WriteLine("Total votes:")
- WriteLine(linecount)
- FileOpen(2, index(count, 1), OpenMode.Input)
- WriteLine("voters:")
- For count2 = 0 To linecount - 1
- WriteLine(LineInput(2))
- Next
- FileClose(2)
- WriteLine("Say 'Stop' to end or enter another character to carry on.")
- If ReadLine() = "stop" Or "Stop" Then
- menu(username)
- End If
- End If
- Next
- Clear()
- Console.WriteLine("Error please re-enter your character")
- GoTo choice
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement