Advertisement
Guest User

Untitled

a guest
Feb 28th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.10 KB | None | 0 0
  1. Option Explicit On
  2.  
  3. Module Module1
  4.  
  5. Sub Main()
  6. Do
  7. Console.Title = "Spelling Bee" 'title
  8. login() 'jumps to the login procedure
  9. Loop
  10. End Sub
  11.  
  12. Sub login()
  13. Dim correctLogin As Boolean = False
  14. Dim intLevel As Integer
  15. Dim strUsername As String
  16.  
  17. Do
  18. Console.Clear()
  19. Console.ForegroundColor = ConsoleColor.DarkGreen
  20. Console.WriteLine("Login")
  21. Console.ForegroundColor = ConsoleColor.White
  22. Console.Write("Username: ")
  23. strUsername = Console.ReadLine
  24. Console.Write("Password: ")
  25. Dim strPassword As String = Console.ReadLine
  26. Console.WriteLine() 'inputs login details
  27.  
  28. If My.Computer.FileSystem.FileExists("C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv") Then
  29. 'If My.Computer.FileSystem.FileExists("\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv") Then
  30. Else 'if accounts database doesnt exist it creates one and creates the admin account
  31. FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Output)
  32. 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Output)
  33. PrintLine(1, "admin,changeme, 1")
  34. FileClose(1)
  35. End If
  36.  
  37. FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
  38. 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
  39. 'opens the file to read from
  40.  
  41. Dim strFullLine As String
  42.  
  43. Do Until EOF(1)
  44. strFullLine = LineInput(1)
  45. Dim strItem() As String = Split(strFullLine, ",")
  46.  
  47. If strItem(0) = strUsername Then
  48. If strItem(1) = strPassword Then
  49. correctLogin = True
  50. intLevel = strItem(2)
  51. Exit Do
  52. End If
  53. End If
  54. Loop
  55.  
  56. FileClose(1) 'checks the login details to the database the closes file
  57.  
  58. If correctLogin = False Then
  59. Console.WriteLine("Incorrect login.")
  60. Threading.Thread.Sleep(1000)
  61. End If
  62.  
  63. Loop Until correctLogin = True
  64.  
  65. Select Case intLevel
  66. Case 1
  67. admin()
  68. Case 2
  69. teacher(strUsername)
  70. Case 3, 4, 5, 6
  71. pupil(intLevel, strUsername)
  72. End Select 'sends the user to the correct account
  73. End Sub
  74.  
  75. Sub admin() '***Add feature to change admin password
  76. Do
  77. Console.Clear()
  78. Console.Title = "Spelling Bee - Admin"
  79. Console.ForegroundColor = ConsoleColor.DarkGreen
  80. Console.WriteLine("Admin panel")
  81. Console.ForegroundColor = ConsoleColor.White
  82. Console.WriteLine("1 - Create account")
  83. Console.WriteLine("2 - Delete account")
  84. Console.WriteLine("3 - View accounts")
  85. Console.WriteLine("4 - Priority levels")
  86. Console.WriteLine("0 - Logout")
  87. Console.WriteLine()
  88. Console.Write("Enter selection: ")
  89. Dim bytChoice As Byte = Console.ReadLine 'make selection
  90.  
  91. Select Case bytChoice 'takes you to the correct sub routine
  92. Case 1
  93. createAccount()
  94. Case 2
  95. deleteAccount()
  96. Case 3
  97. viewAccount()
  98. Case 4
  99. priorityLevels()
  100. Case 0
  101. Exit Sub
  102. Case Else
  103. Console.WriteLine()
  104. Console.WriteLine("Input invalid.") 'validation
  105. Threading.Thread.Sleep(1000)
  106. End Select
  107. Loop
  108. End Sub
  109.  
  110. Sub createAccount() '***Add a function to return to the menu
  111. Dim again As Boolean = True 'swtich to jump out the again loop
  112. Dim strFullLine As String
  113.  
  114. Do
  115. Do
  116. Console.Clear()
  117. Console.ForegroundColor = ConsoleColor.DarkGreen
  118. Console.WriteLine("Admin panel - Create account")
  119. Console.ForegroundColor = ConsoleColor.White
  120. Console.Write("Username: ")
  121. Dim strUsername As String = Console.ReadLine
  122. Console.Write("Password: ")
  123. Dim strPassword As String = Console.ReadLine
  124. Console.Write("Level: ")
  125. Dim intLevel As String = Console.ReadLine
  126.  
  127. strFullLine = strUsername + "," + strPassword + "," + intLevel
  128.  
  129. FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
  130. 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
  131.  
  132. Dim strCheckLine As String = ""
  133.  
  134. Do Until EOF(1)
  135. strCheckLine = LineInput(1)
  136. If strCheckLine = strFullLine Then
  137. Exit Do
  138. End If
  139. Loop
  140.  
  141. FileClose(1) 'checks if the account being created already exists
  142.  
  143. If strCheckLine = strFullLine Then
  144. Console.WriteLine()
  145. Console.WriteLine("This account already exists.")
  146. Threading.Thread.Sleep(1000)
  147. Else
  148. Exit Do
  149. End If
  150. Loop '
  151.  
  152. FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Append)
  153. 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Append)
  154.  
  155. PrintLine(1, strFullLine)
  156.  
  157. FileClose(1) 'stores account
  158.  
  159. Dim intCount As Integer
  160. intCount += 1 'a count to tell the user how many accounts have been created
  161.  
  162. Do
  163. Console.WriteLine()
  164. Console.Write("Would you like to create another account?(Y/N)")
  165. Dim chrChoice As Char = Console.ReadLine
  166. Select Case chrChoice
  167. Case "Y", "y"
  168. Exit Do
  169. Case "N", "n"
  170. again = False
  171. Exit Do
  172. Case Else
  173. Console.WriteLine("Invalid input.")
  174. End Select 'asks if you want to enter another account
  175. Loop
  176.  
  177. If again = False Then
  178. Console.Write("Saving ")
  179. Console.ForegroundColor = ConsoleColor.DarkGreen
  180. Console.Write(intCount)
  181. Console.ForegroundColor = ConsoleColor.White
  182. Console.WriteLine(" accounts to system.")
  183. Console.WriteLine()
  184. Threading.Thread.Sleep(2000)
  185. Exit Do 'displays the amount of accounts created
  186. End If
  187. Loop
  188. End Sub
  189.  
  190. Sub deleteAccount() '***Add a function to return to the menu
  191. Dim found As Boolean = False
  192. Dim intCount As Integer = 0
  193. Dim strCheckLine(1000) As String
  194.  
  195. Do
  196. Console.Clear()
  197. Console.ForegroundColor = ConsoleColor.DarkGreen
  198. Console.WriteLine("Admin panel - Delete account")
  199. Console.ForegroundColor = ConsoleColor.White
  200.  
  201. Console.Write("Username: ")
  202. Dim strUsername As String = Console.ReadLine
  203. Console.Write("Password: ")
  204. Dim strPassword As String = Console.ReadLine
  205. Console.Write("Level: ")
  206. Dim intLevel As String = Console.ReadLine
  207.  
  208. Dim strFullLine As String = ""
  209. strFullLine = strUsername + "," + strPassword + "," + intLevel 'enter the account to delete and stores all values as one string
  210.  
  211. FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
  212. 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
  213.  
  214. Do Until EOF(1)
  215. intCount += 1
  216. strCheckLine(intCount) = LineInput(1)
  217. Loop
  218.  
  219. FileClose(1) 'loads all accounts from csv into an array
  220.  
  221. Dim intCount2 As Integer = 0
  222.  
  223. For intCheck As Integer = 1 To intCount
  224. intCount2 += 1
  225. If strFullLine = strCheckLine(intCount2) Then
  226. strCheckLine(intCount2) = Nothing
  227. found = True
  228. Exit For
  229. End If
  230. Next 'searches for account
  231.  
  232. If found = True Then
  233. Console.WriteLine()
  234. Console.WriteLine("Deleting account...")
  235. Threading.Thread.Sleep(1000)
  236. Exit Do
  237. Else
  238. Console.WriteLine()
  239. Console.WriteLine("User not found.")
  240. Threading.Thread.Sleep(1000)
  241. End If 'if the user was deleted it jumps out the Do Loop else it says User not found and reloops
  242.  
  243. Loop
  244.  
  245. For intCheck2 As Integer = 1 To intCount
  246. If strCheckLine(intCheck2) = Nothing Then
  247. If strCheckLine(intCheck2 + 1) <> Nothing Then
  248. strCheckLine(intCheck2) = strCheckLine(intCheck2 + 1)
  249. strCheckLine(intCheck2 + 1) = Nothing
  250. End If
  251. End If
  252. Next 'sorts the new data removing the blank gap in the csv
  253.  
  254. FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Output)
  255. 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Output)
  256.  
  257. For intSave As Integer = 1 To intCount
  258. PrintLine(1, strCheckLine(intSave))
  259. Next
  260.  
  261. FileClose(1) 'saves over the previous file excluding the deleted accounts
  262. End Sub
  263.  
  264. Sub viewAccount()
  265. Console.Clear()
  266. Console.ForegroundColor = ConsoleColor.DarkGreen
  267. Console.WriteLine("Admin panel - View accounts")
  268. Console.ForegroundColor = ConsoleColor.White
  269. Console.Write("Enter level you wish to view: ")
  270. Dim intLevel As Integer = Console.ReadLine
  271. Console.WriteLine()
  272.  
  273. If intLevel < 1 Or intLevel > 6 Then
  274. Console.WriteLine("Invalid input.")
  275. Console.WriteLine()
  276. End If 'validation
  277.  
  278. FileOpen(1, "C:\Users\Tom\Documents\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
  279. 'FileOpen(1, "\\file-home2\thored15$\Visual Studio 2010\Projects\Spelling Bee Login System\Spelling Bee Login System\accounts.csv", OpenMode.Input)
  280.  
  281. Dim strFullLine As String = ""
  282. Dim check As Boolean = False
  283.  
  284. Do Until EOF(1)
  285. strFullLine = LineInput(1)
  286. Dim strItem() As String = Split(strFullLine, ",")
  287. If strItem(2) = intLevel Then
  288. Console.WriteLine(strFullLine)
  289. check = True
  290. End If
  291. Loop 'allows the user to view the accounts of the selected level
  292.  
  293. If check = False Then
  294. Console.WriteLine("No accounts found.")
  295. End If
  296.  
  297. FileClose(1)
  298.  
  299. Console.WriteLine()
  300. Console.WriteLine("Press enter to return...")
  301. Console.ReadLine()
  302. End Sub
  303.  
  304. Sub priorityLevels()
  305. Console.Clear()
  306. Console.ForegroundColor = ConsoleColor.DarkGreen
  307. Console.WriteLine("Admin panel - Priority levels")
  308. Console.ForegroundColor = ConsoleColor.White
  309.  
  310. Console.WriteLine("1: Admin")
  311. Console.WriteLine("2: Teacher")
  312. Console.WriteLine("3: Year 3")
  313. Console.WriteLine("4: Year 4")
  314. Console.WriteLine("5: Year 5")
  315. Console.WriteLine("6: Year 6")
  316. Console.WriteLine()
  317. Console.WriteLine("Press enter to return...")
  318. Console.ReadLine() 'displays what each priority level is for then takes you back to the admin panel
  319. End Sub
  320.  
  321. Sub teacher(ByVal strUsername As String)
  322. Do
  323. Console.Clear()
  324. Console.Title = "Spelling Bee - " + strUsername
  325. Console.ForegroundColor = ConsoleColor.DarkGreen
  326. Console.WriteLine("Teacher panel")
  327. Console.ForegroundColor = ConsoleColor.White
  328. Console.WriteLine("1 - Add spellings")
  329. Console.WriteLine("2 - View past spellings")
  330. Console.WriteLine("3 - View test results")
  331. Console.WriteLine("0 - Logout")
  332. Console.Write("Enter selection: ")
  333. Dim intChoice As Integer = Console.ReadLine
  334. Select Case intChoice
  335. Case 1
  336. addSpellings()
  337. Case 2
  338. pastSpellings()
  339. Case 3
  340. testResults()
  341. Case 0
  342. Exit Sub
  343. Case Else
  344. Console.WriteLine()
  345. Console.WriteLine("Invalid input.")
  346. Threading.Thread.Sleep(1000)
  347. End Select
  348. Loop
  349. End Sub
  350.  
  351. Sub addSpellings()
  352. Console.Clear()
  353. Console.ForegroundColor = ConsoleColor.DarkGreen
  354. Console.WriteLine("Teacher panel - Add spellings")
  355. Console.ForegroundColor = ConsoleColor.White
  356. End Sub
  357.  
  358. Sub pastSpellings()
  359. Console.Clear()
  360. Console.ForegroundColor = ConsoleColor.DarkGreen
  361. Console.WriteLine("Teacher panel - Past spellings")
  362. Console.ForegroundColor = ConsoleColor.White
  363. End Sub
  364.  
  365. Sub testResults()
  366. Console.Clear()
  367. Console.ForegroundColor = ConsoleColor.DarkGreen
  368. Console.WriteLine("Teacher panel - Test results")
  369. Console.ForegroundColor = ConsoleColor.White
  370. End Sub
  371.  
  372. Sub pupil(ByVal intLevel As Integer, strUsername As String)
  373. Console.Clear()
  374. Console.Title = "Spelling Bee - " 'add pupils user here
  375. Console.ForegroundColor = ConsoleColor.DarkGreen
  376. Console.WriteLine("Spelling test")
  377. Console.ForegroundColor = ConsoleColor.White
  378. End Sub
  379. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement