Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- 'These are my variables'
- Dim i As Integer
- Dim j As Integer
- Dim name As String
- Dim postcode As String
- Dim numberarray(7) As Integer
- Dim check_digit As Integer
- Dim total As Integer
- Dim cardnumber As Integer
- 'This assigns the textboxes'
- name = (Txtname.Text)
- postcode = (Txtpostcode.Text)
- cardnumber = (Txtcardnumber.Text)
- 'This our first array variable which
- For i = 0 To 7
- numberarray(i) = Txtcardnumber.Text.Substring(i, 1)
- Next
- 'this stores the 8th digit as check_digit'
- check_digit = numberarray(7)
- 'This reverses the digits'
- Array.Reverse(numberarray)
- For j = 0 To 6
- numberarray(j) = Txtcardnumber.Text.Substring(j, 1)
- Next
- 'This multiplies the digits'
- numberarray(0) = numberarray(0) * 2
- numberarray(2) = numberarray(2) * 2
- numberarray(4) = numberarray(4) * 2
- numberarray(6) = numberarray(6) * 2
- 'This will take 9 away from the digits if they are greater than 9'
- If numberarray(0) > 9 Then
- numberarray(0) = numberarray(0) - 9
- End If
- If numberarray(2) > 9 Then
- numberarray(2) = numberarray(2) - 9
- End If
- If numberarray(4) > 9 Then
- numberarray(4) = numberarray(4) - 9
- End If
- If numberarray(6) > 9 Then
- numberarray(6) = numberarray(6) - 9
- End If
- 'This is all the digits being added up together'
- total = numberarray(0) + numberarray(1) + numberarray(2) + numberarray(3) + numberarray(4) + numberarray(5) + numberarray(6) + check_digit
- MessageBox.Show(total)
- 'This checks if the total is directly divisible by 10'
- If total Mod 10 = 0 Then
- 'these show the name, postcode, cardnumber and if the cardnumber is valid'
- MessageBox.Show("Name:" & name)
- MessageBox.Show("Postcode:" & postcode)
- MessageBox.Show("cardnumber:" & cardnumber)
- MessageBox.Show("Card is valid")
- MessageBox.Show("Your Loyalty card is Valid")
- 'these show the name, postcode, cardnumber and if the cardnumber is invalid'
- ElseIf MessageBox.Show("Name:" & name) Then
- MessageBox.Show("Postcode:" & postcode)
- MessageBox.Show("cardnumber:" & cardnumber)
- MessageBox.Show("Card is invalid")
- MessageBox.Show("Your Loyalty card is Invalid")
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement