Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Console
  3.  
  4. Module Module1
  5.  
  6. Dim usercohice As String
  7. Dim addfile As String = "N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEM\bin"
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. Sub Main()
  18.  
  19. Dim username2 As String
  20. Dim password As String
  21. 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"
  22. 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"
  23. Dim fileusername As String
  24. Dim filepassword As String
  25. Dim admin_login As String
  26.  
  27.  
  28. 'The filename variable stores the name that the program wants to access
  29. 'This lets vb know the directory that the file should be found in. it also creates a file if
  30. 'one with the following name doesn’t already exist
  31.  
  32. FileOpen(1, filename, OpenMode.Input)
  33. fileusername = (LineInput(1))
  34.  
  35. FileOpen(2, filename2, OpenMode.Input)
  36. filepassword = (LineInput(2))
  37.  
  38. 'once the file is found fileopen will open the file and openmode.input will allow us to change whats in the file
  39.  
  40.  
  41. WriteLine("Welcome to the voting system")
  42.  
  43. WriteLine("To vote you must login") 'introduction code
  44. WriteLine("As an admin you can Add a new character and calculate votes")
  45. WriteLine("Normal login menu will only contain vote for a character option")
  46. WriteLine("Would you like to log on as an ADMIN")
  47. ForegroundColor = ConsoleColor.Green
  48. WriteLine("1) Yes")
  49. ForegroundColor = ConsoleColor.Red
  50. WriteLine("2) No")
  51. admin_login = ReadLine()
  52.  
  53. If admin_login = "Yes" Or admin_login = "yes" Then
  54. WriteLine("Switching to admin login now")
  55. adminLogin()
  56. ElseIf admin_login = "No" Or admin_login = "no" Then
  57. WriteLine("Staying on normal login")
  58. ReadLine()
  59. Clear()
  60. End If
  61.  
  62. WriteLine("please enter your username")
  63. username2 = ReadLine()
  64.  
  65.  
  66.  
  67. While username2 <> fileusername ' a while loop to make sure the user enters the correct username
  68. WriteLine("Incorrect username Please try again")
  69. username2 = ReadLine() 'user will be stuck in this loop until they enter correct username
  70. End While
  71. FileClose(1)
  72.  
  73.  
  74. WriteLine("please enter your password")
  75. password = ReadLine()
  76.  
  77. While password <> filepassword
  78. ' a while loop to make sure the user enters the correct password
  79. WriteLine("Incorrect password please try again")
  80. password = ReadLine() 'like above the user will be stuck in the loop until they enter correct password
  81. End While
  82.  
  83. WriteLine("Login Successful!")
  84. FileClose(2) 'outputs when the user is sucessful with both password and username
  85. mainmenu(username2) 'first sub to take user to the main menu
  86.  
  87. End Sub
  88.  
  89. Sub mainmenu(ByVal username2)
  90.  
  91. Dim choice As Integer
  92. Clear()
  93. WriteLine("Main Menu:")
  94. WriteLine("1. vote for a character")
  95. WriteLine("2. add a new character")
  96. WriteLine("3. calculate final vote")
  97.  
  98. WriteLine(" Please select an option from above")
  99. choice = ReadLine()
  100.  
  101.  
  102. If choice = 1 Then
  103. WriteLine("You chose vote for a character option")
  104. vote(username2)
  105. ElseIf choice = 2 Then
  106. WriteLine("You chose add a new character")
  107. add(username2)
  108. ElseIf choice = 3 Then
  109. WriteLine("You chose calculate final vote option")
  110. calculate()
  111. End If
  112.  
  113.  
  114. While choice <> "1" Or choice <> "2" Or choice <> "3"
  115. WriteLine("Invalid input try again")
  116. choice = ReadLine()
  117. End While
  118.  
  119.  
  120.  
  121.  
  122. End Sub
  123. Sub vote(ByVal username2)
  124.  
  125. Dim filepath2 As String = "N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEMS FILES\index.txt"
  126. Dim filepath As String = "N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEMS FILES\DebugAdd_Character"
  127. Dim lineCount As Integer
  128.  
  129.  
  130.  
  131. lineCount = File.ReadAllLines("N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEMS FILES\index.txt").Length
  132.  
  133. lineCount = (lineCount / 2) - 1
  134.  
  135. Dim index(lineCount, 1)
  136. Dim choice As String
  137.  
  138. FileOpen(1, filepath2, OpenMode.Input)
  139.  
  140. WriteLine("Characters available")
  141. For count = 0 To lineCount
  142. index(count, 1) = LineInput(1)
  143.  
  144. PrintLine(1, index(count, 0))
  145. WriteLine()
  146.  
  147. Next
  148. WriteLine("Who would you like to vote for")
  149.  
  150. choice = ReadLine()
  151.  
  152. For count = 0 To lineCount / 2 - 1
  153. If choice = index(count, 1) Then
  154. WriteLine("Character found getting data...")
  155. Console.Beep()
  156. FileOpen(2, index(count, 0), OpenMode.Input)
  157. WriteLine("You have voted for" & index(count, 0))
  158. ReadLine()
  159. PrintLine(2, username2)
  160. FileClose(2)
  161. FileClose(1)
  162. mainmenu(username2)
  163.  
  164. ElseIf count = lineCount / 2 - 1 Then
  165.  
  166. End If
  167.  
  168. Next
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175. mainmenu(username2)
  176. End Sub
  177. Sub add(ByVal username2)
  178. Dim userchoice As String
  179. Dim addfile As String = "N:\My Documents\YEAR 10\COMPUTER SCIENCE\NE\THE REAL VOTING SYSTEM\THE REAL VOTING SYSTEMS FILES\DebugAdd_Character.txt"
  180.  
  181. FileOpen(1, addfile, OpenMode.Append)
  182.  
  183. ReadLine()
  184. WriteLine("Please enter the Full name of the character you want to add")
  185. WriteLine("Please note that whatever you enter will be submitted as a character to vote for")
  186.  
  187. userchoice = ReadLine()
  188.  
  189. While userchoice <> "stop"
  190.  
  191. PrintLine(1, userchoice)
  192. WriteLine("Please enter another character or type stop to finish")
  193. userchoice = ReadLine()
  194. End While
  195.  
  196. FileClose(1)
  197. mainmenu(username2)
  198.  
  199. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement