Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Console
  3.  
  4.  
  5. Module Module1
  6.  
  7. Sub Main()
  8. Dim repeat As Boolean
  9. Dim username As String
  10. Dim password As String
  11. Dim accounts(8, 1) As String
  12. Dim userver As Boolean = False
  13. Dim filepath As String = "N:\voting assesment 2\storage.txt"
  14.  
  15. Dim length As Integer = File.ReadAllLines(filepath).Length ' stores length of a file
  16. Dim lineCount = File.ReadAllLines(filepath).Length ' count how many lines a file has
  17. FileOpen(1, filepath, OpenMode.Input)
  18.  
  19.  
  20.  
  21. For count = 0 To lineCount / 2 - 1
  22. accounts(count, 0) = LineInput(1)
  23.  
  24. accounts(count, 1) = LineInput(1)
  25.  
  26. Next
  27. WriteLine("usernames")
  28. For count = 0 To lineCount / 2 - 1
  29.  
  30. WriteLine(accounts(count, 0))
  31. Next
  32. WriteLine("passwords")
  33. For count = 0 To lineCount / 2 - 1
  34.  
  35. WriteLine(accounts(count, 1))
  36. Next
  37. username:
  38. WriteLine("Please enter your username")
  39. username = ReadLine()
  40.  
  41. For count = 0 To 8
  42. If username = accounts(count, 0) Then
  43. WriteLine("username found")
  44. userver = True
  45. Do
  46.  
  47.  
  48. WriteLine("please enter your password")
  49. password = ReadLine()
  50. If password = accounts(count, 1) Then
  51. WriteLine("password accepted")
  52. repeat = False
  53. FileClose(1)
  54. menu(username)
  55.  
  56.  
  57. Else
  58. WriteLine("password declined")
  59. repeat = True
  60. End If
  61. Loop Until repeat = False
  62. End If
  63. Next
  64. If userver = False Then
  65. Console.WriteLine("username not found please re-enter")
  66. GoTo username
  67. End If
  68.  
  69. ReadLine()
  70. End Sub
  71. Sub menu(ByVal username)
  72. WriteLine("Welcome " & username)
  73. Dim choice As String
  74. WriteLine("1.Choose your vote")
  75. WriteLine("2. Add a new character")
  76. WriteLine("3.Add up total votes")
  77. choice = Console.ReadLine()
  78. If choice = 1 Then
  79. vote(username)
  80. ElseIf choice = 2 Then
  81. addvote()
  82. ElseIf choice = 3 Then
  83. checkvote(username)
  84. ElseIf choice = 4 Then
  85. dance()
  86. Else : WriteLine("Please re-enter your chice")
  87. End If
  88.  
  89. End Sub
  90. Sub dance()
  91. Do
  92.  
  93. WriteLine(" \*_* ")
  94. WriteLine(" ( (>") ' dance guy 1
  95. WriteLine(" / \ ")
  96. Beep()
  97. Beep()
  98.  
  99.  
  100.  
  101.  
  102. Beep()
  103.  
  104. Beep()
  105. Clear()
  106. WriteLine(" @_@/ ")
  107. WriteLine(" <) ) ") 'dance guy 2
  108. WriteLine(" / \ ")
  109. Beep()
  110. Beep()
  111. Beep()
  112. Clear()
  113. Loop
  114.  
  115.  
  116. End Sub
  117. Sub vote(ByVal username)
  118.  
  119.  
  120.  
  121.  
  122. Dim filepath2 As String = "N:\voting assesment 2\Index.txt"
  123.  
  124. Dim lineCount2 = File.ReadAllLines(filepath2).Length
  125.  
  126. Dim index(lineCount2 / 2 - 1, 1)
  127.  
  128. Dim choice As String
  129.  
  130. FileOpen(1, filepath2, OpenMode.Input)
  131.  
  132.  
  133.  
  134.  
  135.  
  136. WriteLine("Hello " & username & ". Welcome to voting, here you can cast your vote on whoever is available")
  137.  
  138.  
  139.  
  140.  
  141. WriteLine("available characters")
  142. For count = 0 To lineCount2 / 2 - 1
  143. index(count, 0) = LineInput(1)
  144.  
  145. index(count, 1) = LineInput(1)
  146.  
  147. WriteLine(index(count, 0))
  148. WriteLine()
  149.  
  150.  
  151. Next
  152.  
  153. WriteLine("Who would you like to vote for? ^")
  154.  
  155. choice = ReadLine()
  156.  
  157. For count = 0 To lineCount2 / 2 - 1
  158.  
  159. If choice = index(count, 0) Then
  160. WriteLine("Character found. Getting data...")
  161. FileOpen(2, index(count, 1), OpenMode.Append)
  162. WriteLine("You have voted for" & index(count, 0))
  163. ReadLine()
  164. PrintLine(2, username)
  165. FileClose(2)
  166. FileClose(1)
  167. menu(username)
  168.  
  169.  
  170. ElseIf count = lineCount2 / 2 - 1 Then
  171. End If
  172.  
  173. Next
  174.  
  175.  
  176. End Sub
  177. Sub addvote()
  178. Dim chara As String
  179. Dim charver As String
  180. Dim filepath2 As String = "N:\voting assesment 2\Index.txt"
  181.  
  182. Dim lineCount = File.ReadAllLines(filepath2).Length
  183.  
  184.  
  185.  
  186.  
  187.  
  188. FileOpen(1, filepath2, OpenMode.Append)
  189.  
  190.  
  191. WriteLine("Welcome to add vote")
  192.  
  193. name:
  194. WriteLine("Please enter your characters name.")
  195. chara = ReadLine()
  196. WriteLine("Please verify your characters name.")
  197. charver = ReadLine()
  198. If charver = chara Then
  199. WriteLine("Characters match! Exporting data.")
  200. Dim path As String = "C:\voting assesment 2\Characters\" & chara & ".txt"
  201. WriteLine("Character file created @" & path)
  202.  
  203. File.Create("C:\voting assesment 2\Characters\" & chara & ".txt")
  204. PrintLine(1, chara)
  205. PrintLine(1, path)
  206.  
  207.  
  208. ElseIf charver <> chara Then
  209. Clear()
  210. WriteLine("Names did not match please try again")
  211.  
  212. GoTo name
  213. End If
  214.  
  215.  
  216. End Sub
  217. Sub checkvote(ByVal username)
  218. Clear()
  219.  
  220. Dim filepath2 As String = "N:\voting assesment 2\Index.txt"
  221.  
  222. Dim lineCount2 = File.ReadAllLines(filepath2).Length
  223.  
  224. Dim index(lineCount2 / 2 - 1, 1)
  225.  
  226. Dim choice As String
  227.  
  228. FileOpen(1, filepath2, OpenMode.Input)
  229.  
  230.  
  231.  
  232.  
  233.  
  234. WriteLine("Hello " & username & ". Welcome to total votes here you can check each character and see how many votes they have and who has voted")
  235.  
  236.  
  237.  
  238.  
  239.  
  240. For count = 0 To lineCount2 / 2 - 1
  241. index(count, 0) = LineInput(1)
  242.  
  243. index(count, 1) = LineInput(1)
  244.  
  245.  
  246.  
  247. Next
  248. choice:
  249. WriteLine("available characters")
  250. For count = 0 To lineCount2 / 2 - 1
  251.  
  252.  
  253. WriteLine(index(count, 0))
  254. WriteLine()
  255.  
  256.  
  257. Next
  258.  
  259.  
  260.  
  261. WriteLine("please choose a character to display extra data")
  262. choice = ReadLine()
  263.  
  264. For count = 0 To lineCount2 / 2 - 1
  265.  
  266. If choice = index(count, 0) Then
  267. Dim linecount As String = File.ReadAllLines(index(count, 1)).Length
  268.  
  269. WriteLine("Character found. Loading")
  270. For count2 = 0 To 5
  271. Write(".")
  272. Beep()
  273.  
  274. Next
  275. WriteLine(" Done")
  276. Beep()
  277. Beep()
  278. Beep()
  279. Clear()
  280.  
  281.  
  282.  
  283. WriteLine("Total votes:")
  284.  
  285.  
  286. WriteLine(linecount)
  287. FileOpen(2, index(count, 1), OpenMode.Input)
  288. WriteLine("voters:")
  289. For count2 = 0 To linecount - 1
  290.  
  291. WriteLine(LineInput(2))
  292.  
  293. Next
  294. FileClose(2)
  295.  
  296. WriteLine("Say 'Stop' to end or enter another character to carry on.")
  297.  
  298.  
  299. If ReadLine() = "stop" Or "Stop" Then
  300. menu(username)
  301.  
  302. End If
  303.  
  304.  
  305.  
  306.  
  307. End If
  308.  
  309. Next
  310. Clear()
  311.  
  312. Console.WriteLine("Error please re-enter your character")
  313.  
  314. GoTo choice
  315. End Sub
  316.  
  317. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement