Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         'These are my variables'
  5.        Dim i As Integer
  6.         Dim j As Integer
  7.  
  8.         Dim name As String
  9.         Dim postcode As String
  10.         Dim numberarray(7) As Integer
  11.         Dim check_digit As Integer
  12.         Dim total As Integer
  13.         Dim cardnumber As Integer
  14.         'This assigns the textboxes'
  15.        name = (Txtname.Text)
  16.         postcode = (Txtpostcode.Text)
  17.         cardnumber = (Txtcardnumber.Text)
  18.         'This our first array variable which
  19.        For i = 0 To 7
  20.             numberarray(i) = Txtcardnumber.Text.Substring(i, 1)
  21.         Next
  22.         'this stores the 8th digit as check_digit'
  23.        check_digit = numberarray(7)
  24.         'This reverses the digits'
  25.        Array.Reverse(numberarray)
  26.  
  27.         For j = 0 To 6
  28.             numberarray(j) = Txtcardnumber.Text.Substring(j, 1)
  29.         Next
  30.         'This multiplies the digits'
  31.        numberarray(0) = numberarray(0) * 2
  32.         numberarray(2) = numberarray(2) * 2
  33.         numberarray(4) = numberarray(4) * 2
  34.         numberarray(6) = numberarray(6) * 2
  35.         'This will take 9 away from the digits if they are greater than 9'
  36.        If numberarray(0) > 9 Then
  37.             numberarray(0) = numberarray(0) - 9
  38.         End If
  39.  
  40.         If numberarray(2) > 9 Then
  41.             numberarray(2) = numberarray(2) - 9
  42.         End If
  43.  
  44.         If numberarray(4) > 9 Then
  45.             numberarray(4) = numberarray(4) - 9
  46.         End If
  47.  
  48.         If numberarray(6) > 9 Then
  49.             numberarray(6) = numberarray(6) - 9
  50.         End If
  51.         'This is all the digits being added up together'
  52.        total = numberarray(0) + numberarray(1) + numberarray(2) + numberarray(3) + numberarray(4) + numberarray(5) + numberarray(6) + check_digit
  53.  
  54.         MessageBox.Show(total)
  55.         'This checks if the total is directly divisible by 10'
  56.        If total Mod 10 = 0 Then
  57.             'these show the name, postcode, cardnumber and if the cardnumber is valid'
  58.            MessageBox.Show("Name:" & name)
  59.             MessageBox.Show("Postcode:" & postcode)
  60.             MessageBox.Show("cardnumber:" & cardnumber)
  61.             MessageBox.Show("Card is valid")
  62.             MessageBox.Show("Your Loyalty card is Valid")
  63.             'these show the name, postcode, cardnumber and if the cardnumber is invalid'
  64.        ElseIf MessageBox.Show("Name:" & name) Then
  65.             MessageBox.Show("Postcode:" & postcode)
  66.             MessageBox.Show("cardnumber:" & cardnumber)
  67.             MessageBox.Show("Card is invalid")
  68.             MessageBox.Show("Your Loyalty card is Invalid")
  69.  
  70.         End If
  71.     End Sub
  72. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement