Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.Security.Cryptography
- Imports System.Text
- Module Module1
- Structure userBlueprint
- Dim id As Integer
- Dim username As String
- Dim password As String
- Dim fname As String
- Dim sname As String
- Dim points As Integer
- End Structure
- Structure formBlueprint
- Dim id As Integer
- Dim name As String
- Dim password As String
- Dim fname As String
- Dim sname As String
- End Structure
- Dim activeuser As userBlueprint
- Dim userdb(100) As userBlueprint
- Dim activeform As formBlueprint
- Dim formdb(100) As formBlueprint
- Function GetHash(theInput As String) As String
- Using hasher As MD5 = MD5.Create() ' create hash object
- ' Convert to byte array and get hash
- Dim dbytes As Byte() =
- hasher.ComputeHash(Encoding.UTF8.GetBytes(theInput))
- ' sb to create string from bytes
- Dim sBuilder As New StringBuilder()
- ' convert byte data to hex string
- For n As Integer = 0 To dbytes.Length - 1
- sBuilder.Append(dbytes(n).ToString("X2"))
- Next n
- Return sBuilder.ToString()
- End Using
- End Function
- Sub Main()
- Console.WriteLine("1 - Teacher")
- Console.WriteLine("2 - Student")
- Console.WriteLine("3 - exit")
- Dim choice As Integer
- Do
- Try
- choice = Console.ReadLine()
- Exit Do
- Catch ex As Exception
- Console.WriteLine("Error")
- Console.Clear()
- End Try
- Loop
- If choice = 1 Then
- Console.Clear()
- formchoice()
- End If
- If choice = 2 Then
- Console.Clear()
- userchoice()
- End If
- If choice = 3 Then
- End
- End If
- End Sub
- Sub spendpoints()
- Console.WriteLine("You have " + activeuser.points.ToString + " to spend.")
- Console.WriteLine("1 - Set of pens for 25 points.")
- Console.WriteLine("2 - Football for 50 points.")
- Console.WriteLine("3 - CD voucher for 60 points.")
- Console.WriteLine("4 - Memory stick for 100 points.")
- Console.WriteLine("5 - An ice skating voucher for 110 points.")
- Console.WriteLine("6 - A computer game for 150 points.")
- Console.WriteLine("7 - A driving lesson for 250 points.")
- Console.WriteLine("8 - A digital camera for 300 points.")
- Console.WriteLine("9 - An mp3 player for 400 points.")
- Console.WriteLine("10 - A games console for 500 points.")
- Dim buychoice = Console.ReadLine
- If buychoice = 1 And activeuser.points > 25 Then
- Console.WriteLine("You have redeemed your pens")
- activeuser.points = activeuser.points - 25
- spendpoints()
- Else Console.WriteLine("Please select again")
- Console.ReadLine()
- End If
- If buychoice = 2 And activeuser.points > 50 Then
- Console.WriteLine("You have redeemed a football")
- activeuser.points = activeuser.points - 50
- spendpoints()
- Else Console.WriteLine("Please select again")
- Console.ReadLine()
- End If
- If buychoice = 3 And activeuser.points > 60 Then
- Console.WriteLine("You have redeemed a CD voucher")
- activeuser.points = activeuser.points - 60
- spendpoints()
- Else Console.WriteLine("Please select again")
- Console.ReadLine()
- End If
- If buychoice = 4 And activeuser.points > 100 Then
- Console.WriteLine("You have redeemed a memory stick")
- activeuser.points = activeuser.points - 100
- spendpoints()
- Else Console.WriteLine("Please select again")
- Console.ReadLine()
- End If
- If buychoice = 5 And activeuser.points > 110 Then
- Console.WriteLine("You have redeemed an ice skating voucher")
- activeuser.points = activeuser.points - 110
- spendpoints()
- Else Console.WriteLine("Please select again")
- Console.ReadLine()
- End If
- If buychoice = 6 And activeuser.points > 150 Then
- Console.WriteLine("You have redeemed a computer game")
- activeuser.points = activeuser.points - 150
- spendpoints()
- Else Console.WriteLine("Please select again")
- Console.ReadLine()
- End If
- If buychoice = 7 And activeuser.points > 250 Then
- Console.WriteLine("You have redeemed a driving lesson")
- activeuser.points = activeuser.points - 250
- spendpoints()
- Else Console.WriteLine("Please select again")
- Console.ReadLine()
- End If
- If buychoice = 8 And activeuser.points > 300 Then
- Console.WriteLine("You have redeemed a digital camera")
- activeuser.points = activeuser.points - 300
- spendpoints()
- Else Console.WriteLine("Please select again")
- Console.ReadLine()
- End If
- If buychoice = 9 And activeuser.points > 400 Then
- Console.WriteLine("You have redeemed an mp3 player")
- activeuser.points = activeuser.points - 400
- spendpoints()
- Else Console.WriteLine("Please select again")
- Console.ReadLine()
- End If
- If buychoice = 10 And activeuser.points > 500 Then
- Console.WriteLine("You have redeemed a games console")
- activeuser.points = activeuser.points - 500
- spendpoints()
- Else Console.WriteLine("Please select again")
- Console.ReadLine()
- End If
- End Sub
- Sub userchoice()
- Console.WriteLine("1 - Login")
- Console.WriteLine("2 - Create")
- Dim choice As Integer = Console.ReadLine
- If choice = 1 Then userlogin()
- If choice = 2 Then adduser()
- End Sub
- Sub formchoice()
- Console.WriteLine("1 - Login")
- Console.WriteLine("2 - Create")
- Dim choice As Integer = Console.ReadLine
- If choice = 1 Then formlogin()
- If choice = 2 Then addteacher()
- End Sub
- Sub useroptions()
- Console.WriteLine("1 - Spend points")
- Console.WriteLine("2 - See points")
- Dim choice As Integer = Console.ReadLine
- If choice = 1 Then
- spendpoints()
- If choice = 2 Then
- Console.WriteLine(activeuser.points)
- Console.ReadLine()
- End If
- End If
- End Sub
- Sub formoptions()
- Console.Clear()
- Console.WriteLine("Add poitns to students - 1")
- Console.WriteLine("Take points from students - 2")
- Dim choice As Integer = Console.ReadLine
- If choice = 1 Then
- addpoints()
- ElseIf choice = 2 Then
- takepoints()
- End If
- End Sub
- Sub formlogin()
- readstaff()
- Console.Write("Username: ")
- Dim searchcriteria As String = Console.ReadLine()
- Console.Write("Password : ")
- Dim searchcriteria2 As String = Console.ReadLine()
- For i = 0 To formdb.Length - 1
- If searchcriteria2 <> Nothing And searchcriteria <> Nothing And searchcriteria = formdb(i).name And searchcriteria2 = formdb(i).password Then
- activeform = formdb(i)
- formoptions()
- End If
- Next
- End Sub
- Sub userlogin()
- readstudent()
- Console.Write("Username: ")
- Dim searchcriteria As String = Console.ReadLine()
- Console.Write("Password : ")
- Dim searchcriteria2 As String = Console.ReadLine()
- For i = 0 To userdb.Length - 1
- If searchcriteria = userdb(i).username And searchcriteria2 = userdb(i).password Then
- activeuser = userdb(i)
- End If
- Next
- useroptions()
- End Sub
- Sub takepoints()
- Console.WriteLine("Which user do you want to take points from? ")
- Console.WriteLine("Type students username:")
- Dim searchcriteria As String = Console.ReadLine()
- For i = 0 To userdb.Length - 1
- If searchcriteria = userdb(i).username Then
- activeuser = userdb(i)
- Console.WriteLine("How many points ")
- Dim points As Integer = Console.ReadLine
- activeuser.points = activeuser.points - points
- Exit Sub
- Else
- Exit Sub
- End If
- Next
- writefileStudent()
- End Sub
- Sub addpoints()
- Console.WriteLine("Which user do you want to give points? ")
- Console.WriteLine("Type students username:")
- Dim searchcriteria As String = Console.ReadLine()
- For i = 0 To userdb.Length - 1
- If searchcriteria = userdb(i).username Then
- activeuser = userdb(i)
- Console.WriteLine("How many points ")
- Dim points As Integer = Console.ReadLine
- activeuser.points = activeuser.points + points
- Exit Sub
- Else
- Exit Sub
- End If
- Next
- writefileStudent()
- End Sub
- Sub addteacher()
- For i = 0 To formdb.Length - 1
- If formdb(i).id = Nothing Then
- activeform.id = i
- Exit For
- End If
- Next
- AddUser("Username: ", activeform.name)
- AddUser("Password: ", activeform.password)
- AddUser("First name: ", activeform.fname)
- AddUser("Surname: ", activeform.sname)
- formdb(activeform.id) = activeform
- writefileStaff()
- End Sub
- Sub adduser()
- For i = 0 To userdb.Length - 1
- If userdb(i).id = Nothing Then
- activeuser.id = i
- Exit For
- End If
- Next
- AddUser("Username: ", activeuser.username)
- AddUser("Password: ", activeuser.password)
- AddUser("First name: ", activeuser.fname)
- AddUser("Surname: ", activeuser.sname)
- userdb(activeuser.id) = activeuser
- writefileStudent()
- End Sub
- Sub writefileStaff()
- Dim filetext As String
- For i = 0 To formdb.Length - 1
- filetext = filetext + formdb(i).id.ToString
- filetext = filetext + "," + formdb(i).name
- filetext = filetext + "," + formdb(i).password
- filetext = filetext + "," + formdb(i).fname
- filetext = filetext + "," + formdb(i).sname + ";"
- Next
- My.Computer.FileSystem.WriteAllText("staff.txt", filetext, False)
- End Sub
- Sub readstaff()
- Dim filetext As String = My.Computer.FileSystem.ReadAllText("staff.txt")
- Dim record() As String = filetext.Split(";")
- For i = 0 To record.Length - 1
- Dim field() As String = record(i).Split(",")
- If field(0) <> Nothing Then
- activeform.id = field(0)
- activeform.name = field(1)
- activeform.password = field(2)
- activeform.fname = field(3)
- activeform.sname = field(4)
- formdb(activeform.id) = activeform
- End If
- Next
- End Sub
- Sub writefileStudent()
- Dim filetext As String
- For i = 0 To userdb.Length - 1
- filetext = filetext + userdb(i).id.ToString
- filetext = filetext + "," + userdb(i).username
- filetext = filetext + "," + userdb(i).password
- filetext = filetext + "," + userdb(i).fname
- filetext = filetext + "," + userdb(i).sname
- filetext = filetext + "," + userdb(i).points.ToString + ";"
- Next
- My.Computer.FileSystem.WriteAllText("student.txt", filetext, False)
- End Sub
- Sub readstudent()
- Dim filetext As String = My.Computer.FileSystem.ReadAllText("student.txt")
- Dim record() As String = filetext.Split(";")
- For i = 0 To record.Length - 1
- Dim field() As String = record(i).Split(",")
- If field(0) <> Nothing Then
- activeuser.id = field(0)
- activeuser.username = field(1)
- activeuser.password = field(2)
- activeuser.fname = field(3)
- activeuser.sname = field(4)
- activeuser.points = field(5)
- userdb(activeuser.id) = activeuser
- End If
- Next
- End Sub
- Sub AddUser(ByVal text As String, ByRef variable As String)
- Do
- Try
- Console.Write(text)
- variable = Console.ReadLine
- Exit Do
- Catch ex As Exception
- Console.WriteLine("Error: Please try again")
- End Try
- Loop
- End Sub
- Sub AddUser(ByVal text As String, ByRef variable As Integer)
- Do
- Try
- Console.Write(text)
- variable = Console.ReadLine
- Exit Do
- Catch ex As Exception
- Console.WriteLine("Error: Please try again")
- End Try
- Loop
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement