Advertisement
Guest User

Untitled

a guest
Jan 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Threading
  2. Module Module1
  3.  
  4.     Dim firstName, lastName, phoneNumber, Address, Email, Password, Username As String
  5.     Dim cardNumber, securityNumber As Integer
  6.     Dim Balance As Decimal
  7.  
  8.     Public Function NewCardNumber()
  9.         Dim num As String
  10.         Dim CardNumTaken As Boolean = False
  11.         Dim loopState = True
  12.  
  13.         While loopState = True
  14.             loopState = False
  15.             Randomize()
  16.             cardNumber = Int(Rnd() * 99999999)
  17.  
  18.             Using file = My.Computer.FileSystem.OpenTextFileReader("C:\Database\CardNumbers.txt")
  19.                 Do
  20.                     num = file.ReadLine()
  21.                     If cardNumber = num Then
  22.                         Console.WriteLine("Test")
  23.                         CardNumTaken = True
  24.                     End If
  25.  
  26.                     If CardNumTaken = True And num = "" Then
  27.                         loopState = True
  28.                         CardNumTaken = False
  29.                     End If
  30.                 Loop Until num = "" And CardNumTaken = False
  31.             End Using
  32.         End While
  33.  
  34.         Using file = My.Computer.FileSystem.OpenTextFileWriter("C:\Database\CardNumbers.txt", True)
  35.             file.WriteLine(cardNumber)
  36.         End Using
  37.  
  38.         Return cardNumber
  39.  
  40.     End Function
  41.  
  42.     Sub CreateFile()
  43.  
  44.         Using file = My.Computer.FileSystem.OpenTextFileWriter("C:\Database\" & Username & ".txt", True)
  45.             file.WriteLine(Password)
  46.             file.WriteLine(cardNumber)
  47.             file.WriteLine(securityNumber)
  48.             file.WriteLine(Balance)
  49.             file.WriteLine(firstName)
  50.             file.WriteLine(lastName)
  51.             file.WriteLine(Address)
  52.             file.WriteLine(phoneNumber)
  53.             file.WriteLine(Email)
  54.         End Using
  55.  
  56.     End Sub
  57.  
  58.     Public Function CheckUser(ByVal user)
  59.         Dim Found As Boolean
  60.         For Each foundFile As String In My.Computer.FileSystem.GetFiles("C:\Database")
  61.             If ("C:\Database\" & user & ".txt") = foundFile Then
  62.                 Found = True
  63.                 Return True
  64.             End If
  65.         Next
  66.  
  67.         If Found = False Then
  68.             Return False
  69.         End If
  70.  
  71.     End Function
  72.  
  73.     Sub Update(ByVal user, one, two, three, four, five, six, seven, eight, nine)
  74.         My.Computer.FileSystem.DeleteFile("C:\Database\" & user & ".txt")
  75.         Using file = My.Computer.FileSystem.OpenTextFileWriter("C:\Database\" & user & ".txt", True)
  76.             file.WriteLine(one)
  77.             file.WriteLine(two)
  78.             file.WriteLine(three)
  79.             file.WriteLine(four)
  80.             file.WriteLine(five)
  81.             file.WriteLine(six)
  82.             file.WriteLine(seven)
  83.             file.WriteLine(eight)
  84.             file.WriteLine(nine)
  85.         End Using
  86.     End Sub
  87.  
  88.     Sub SendMoney(ByVal amount, ByVal user)
  89.         Dim info(8)
  90.         Balance -= amount
  91.         Using contents = My.Computer.FileSystem.OpenTextFileReader("C:\Database\" & user & ".txt")
  92.             For i = 0 To 8
  93.                 info(i) = contents.ReadLine()
  94.             Next
  95.         End Using
  96.  
  97.         info(3) += amount
  98.  
  99.         Update(user, info(0), info(1), info(2), info(3), info(4), info(5), info(6), info(7), info(8))
  100.  
  101.     End Sub
  102.  
  103.     Sub Deposit()
  104.         Console.Write("This is where the ATM would input money. Instead write the amount: ")
  105.         Balance += Console.ReadLine()
  106.     End Sub
  107.  
  108.     Sub SignUp()
  109.         Dim usernameIsFree As Boolean
  110.         Do
  111.             usernameIsFree = True
  112.  
  113.             Console.Write("Username (At least 8 characters) ")
  114.             Username = Console.ReadLine()
  115.  
  116.             For Each foundFile As String In My.Computer.FileSystem.GetFiles("C:\Database")
  117.                 If ("N\Database\" & Username & ".txt") = foundFile Then
  118.                     usernameIsFree = False
  119.                     Console.WriteLine("Username Is taken.")
  120.                 End If
  121.             Next
  122.  
  123.         Loop Until usernameIsFree = True And Username.Count() >= 8
  124.  
  125.         Do
  126.             Console.Write("Password (At least 8 characters) ")
  127.             Password = Console.ReadLine()
  128.         Loop Until Password.Count() >= 8
  129.  
  130.         Console.Write("First Name ")
  131.         firstName = Console.ReadLine()
  132.         Console.Write("Last Name ")
  133.         lastName = Console.ReadLine()
  134.         Console.Write("Phone Number ")
  135.         phoneNumber = Console.ReadLine()
  136.         Console.Write("Address ")
  137.         Address = Console.ReadLine()
  138.         Console.Write("Email ")
  139.         Email = Console.ReadLine()
  140.         Randomize()
  141.         securityNumber = Int(Rnd() * 999)
  142.         Console.Write("Your security number Is {0}. Write it down And don't forget it.", securityNumber)
  143.         Console.WriteLine("Your card number is {0}", NewCardNumber())
  144.         CreateFile()
  145.  
  146.     End Sub
  147.  
  148.     Sub Login()
  149.         Dim usernameExists As Boolean = False
  150.         Dim info(8) As String
  151.  
  152.         Do
  153.             usernameExists = False
  154.             Console.Write("Username: ")
  155.             Username = Console.ReadLine()
  156.  
  157.             For Each foundFile As String In My.Computer.FileSystem.GetFiles("C:\Database")
  158.                 If ("C:\Database\" & Username & ".txt") = foundFile Then
  159.                     usernameExists = True
  160.                 End If
  161.             Next
  162.  
  163.         Loop Until usernameExists = True
  164.  
  165.         Using contents = My.Computer.FileSystem.OpenTextFileReader("C:\Database\" & Username & ".txt")
  166.             For i = 0 To 8
  167.                 info(i) = contents.ReadLine()
  168.             Next
  169.         End Using
  170.  
  171.         Password = info(0)
  172.         cardNumber = info(1)
  173.         securityNumber = info(2)
  174.         Balance = info(3)
  175.         firstName = info(4)
  176.         lastName = info(5)
  177.         Address = info(6)
  178.         phoneNumber = info(7)
  179.         Email = info(8)
  180.  
  181.         Dim tempPassword, tempSecurityNumber As String
  182.         Dim attempts As Integer = 0
  183.  
  184.         Do
  185.             attempts += 1
  186.             Console.Write("Password (Attempt {0}/3): ", attempts)
  187.             tempPassword = Console.ReadLine()
  188.             If tempPassword = Password Then
  189.                 Console.WriteLine("Welcome!")
  190.             ElseIf attempts = 3 Then
  191.                 Console.WriteLine("You've ran out of attempts and will be locked out for 5minutes.")
  192.                 System.Threading.Thread.Sleep(300000)
  193.                 attempts = 0
  194.             Else
  195.                 Console.WriteLine("Please try again.")
  196.             End If
  197.  
  198.         Loop Until tempPassword = Password
  199.  
  200.         Do
  201.             Console.Write("Security Number (On back of the card or noted down): ")
  202.             tempSecurityNumber = Console.ReadLine()
  203.         Loop Until tempSecurityNumber = securityNumber
  204.  
  205.     End Sub
  206.  
  207.     Sub Main()
  208.         Dim input, Send As Integer
  209.         Dim user As String
  210.         Dim runningState As Boolean = True
  211.         Dim Proceed As Boolean = True
  212.  
  213.         While runningState = True
  214.             Console.Clear()
  215.             Console.WriteLine("Welcome to Jordan's the online banking application.")
  216.             Console.Write("To login type 1, to signup type 2: ")
  217.  
  218.             Do
  219.                 input = Console.ReadLine()
  220.                 If input = 1 Then
  221.                     Login()
  222.                 ElseIf input = 2 Then
  223.                     SignUp()
  224.                 Else
  225.                     Console.WriteLine("Incorrect input. Please try again.")
  226.                 End If
  227.             Loop Until input = 1 Or input = 2
  228.  
  229.             Console.WriteLine("Welcome {0}, your balance is £{1}", firstName, Balance)
  230.             Console.WriteLine("To deposit money press 1, to Send money press 2.")
  231.  
  232.             Do
  233.                 input = Console.ReadLine()
  234.                 If input = 1 Then
  235.                     Deposit()
  236.                     Console.WriteLine("Your new balance is £{0}. Thank you for using our ATM", Balance)
  237.                 ElseIf input = 2 Then
  238.                     Do
  239.                         Proceed = True
  240.                         Console.Write("How much money do you want to send?: ")
  241.                         Send = Console.ReadLine()
  242.                         Console.Write("Whats the username of the person you want to send money to?: ")
  243.                         user = Console.ReadLine()
  244.                         If Send > Balance Or Send < 0.01 Then
  245.                             Proceed = False
  246.                             Console.WriteLine("Invalid amount.")
  247.                         End If
  248.                         If CheckUser(user) = False Then
  249.                             Proceed = False
  250.                             Console.WriteLine("Invalid username.")
  251.                         End If
  252.                     Loop Until Proceed = True
  253.                     SendMoney(Send, user)
  254.                     Console.WriteLine("Your new balance is £{0}. Thank you for using our ATM", Balance)
  255.                 Else
  256.                     Console.WriteLine("Either 1 or 2.")
  257.                 End If
  258.  
  259.             Loop Until input = 1 Or input = 2
  260.             Update(Username, Password, cardNumber, securityNumber, Balance, firstName, lastName, Address, phoneNumber, Email)
  261.             System.Threading.Thread.Sleep(10000)
  262.         End While
  263.     End Sub
  264.  
  265. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement