Public Function fValidateBankAccount(lngBankNumber As Long, _
lngBranch As Long, _
lngAccount As Long) As Boolean
fValidateBankAccount = False
Dim lngRequiredAccountLength As Long
Dim lngTotal As Long
Dim strArrayAccount() As String
Dim strArrayBranch() As String
Dim strAccount As String
Dim strBranch As String
Select Case lngBankNumber
Case 10, 13, 34
lngRequiredAccountLength = 8
Case 12, 4
lngRequiredAccountLength = 6
Case 11, 17
lngRequiredAccountLength = 9
Case 20
lngRequiredAccountLength = 6
Case 31, 52
lngRequiredAccountLength = 9
Case 9
lngRequiredAccountLength = 9
Case 22
lngRequiredAccountLength = 9
Case 46
lngRequiredAccountLength = 9
Case 14
lngRequiredAccountLength = 9
End Select
If lngBankNumber <> 54 Then
strAccount = String(lngRequiredAccountLength - Len(CStr(Left(lngAccount, lngRequiredAccountLength))), "0") & CStr(Left(lngAccount, lngRequiredAccountLength))
Else
strAccount = CStr(lngAccount)
End If
' strAccount = Right("0000000000" & CStr(lngAccount), lngRequiredAccountLength) ' This is an alternative to the previous line
strAccount = StrConv(strAccount, vbUnicode)
strArrayAccount = Split(strAccount, vbNullChar)
If lngBankNumber = 20 And lngBranch > 400 Then ' a`i' i^n~o^? a"n~?e'o' a'a'?ן¿½ i^??c,e'-e`o^c,a*u' a^a~a*i` i^400
strBranch = CStr(lngBranch - 400) ' i`o^?e' a"c,e'u`a*a'e'i' e'u` i`a"o^c,e'u' 400
Else
strBranch = lngBranch
End If
If Len(strBranch) < 3 Then
strBranch = String(3 - Len(strBranch), "0") & strBranch ' i^a*n~e'o' a`o^n~e'i' i`a"u`i`e'i' i`3 n~o^?a*u'
End If
strBranch = StrConv(strBranch, vbUnicode)
strArrayBranch = Split(strBranch, vbNullChar)
Select Case lngBankNumber
Case 54
' i`a'?ן¿½ e'?a*u`i`e'i' a`e'i" a`e'i^a*u', e"i` c,u`a'a*i" u'ן¿½e'i"
fValidateBankAccount = True
Case 10, 13, 34
Select Case CLng(Right( _
CLng(strArrayBranch(0)) * 10 + _
CLng(strArrayBranch(1)) * 9 + _
CLng(strArrayBranch(2)) * 8 + _
CLng(strArrayAccount(0)) * 7 + _
CLng(strArrayAccount(1)) * 6 + _
CLng(strArrayAccount(2)) * 5 + _
CLng(strArrayAccount(3)) * 4 + _
CLng(strArrayAccount(4)) * 3 + _
CLng(strArrayAccount(5)) * 2 + _
CLng(Right(lngAccount, 2)) _
, 2))
Case 90, 72, 70, 60, 20
fValidateBankAccount = True
Case Else
fValidateBankAccount = False
End Select
Case 12, 4
lngTotal = CLng(strArrayBranch(0)) * 9 + _
CLng(strArrayBranch(1)) * 8 + _
CLng(strArrayBranch(2)) * 7 + _
CLng(strArrayAccount(0)) * 6 + _
CLng(strArrayAccount(1)) * 5 + _
CLng(strArrayAccount(2)) * 4 + _
CLng(strArrayAccount(3)) * 3 + _
CLng(strArrayAccount(4)) * 2 + _
CLng(strArrayAccount(5)) * 1
Select Case lngTotal Mod 11
Case 0, 2
fValidateBankAccount = True
Case 4, 6
Select Case lngBankNumber
Case 12
fValidateBankAccount = True
Case Else
fValidateBankAccount = False
End Select
Case Else
fValidateBankAccount = False
End Select
Case 11, 17
lngTotal = CLng(strArrayAccount(0)) * 9 + _
CLng(strArrayAccount(1)) * 8 + _
CLng(strArrayAccount(2)) * 7 + _
CLng(strArrayAccount(3)) * 6 + _
CLng(strArrayAccount(4)) * 5 + _
CLng(strArrayAccount(5)) * 4 + _
CLng(strArrayAccount(6)) * 3 + _
CLng(strArrayAccount(7)) * 2 + _
CLng(strArrayAccount(8)) * 1
Select Case lngTotal Mod 11
Case 0, 2, 4
fValidateBankAccount = True
Case Else
fValidateBankAccount = False
End Select
Case 20
lngTotal = CLng(strArrayBranch(0)) * 9 + _
CLng(strArrayBranch(1)) * 8 + _
CLng(strArrayBranch(2)) * 7 + _
CLng(strArrayAccount(0)) * 6 + _
CLng(strArrayAccount(1)) * 5 + _
CLng(strArrayAccount(2)) * 4 + _
CLng(strArrayAccount(3)) * 3 + _
CLng(strArrayAccount(4)) * 2 + _
CLng(strArrayAccount(5)) * 1
Select Case lngTotal Mod 11
Case 0, 2, 4
fValidateBankAccount = True
End Select
Case 31, 52
lngTotal = CLng(strArrayAccount(0)) * 9 + _
CLng(strArrayAccount(1)) * 8 + _
CLng(strArrayAccount(2)) * 7 + _
CLng(strArrayAccount(3)) * 6 + _
CLng(strArrayAccount(4)) * 5 + _
CLng(strArrayAccount(5)) * 4 + _
CLng(strArrayAccount(6)) * 3 + _
CLng(strArrayAccount(7)) * 2 + _
CLng(strArrayAccount(8)) * 1
Select Case lngTotal Mod 11
Case 0, 6
fValidateBankAccount = True
Case Else
lngTotal = CLng(strArrayAccount(3)) * 6 + _
CLng(strArrayAccount(4)) * 5 + _
CLng(strArrayAccount(5)) * 4 + _
CLng(strArrayAccount(6)) * 3 + _
CLng(strArrayAccount(7)) * 2 + _
CLng(strArrayAccount(8)) * 1
If lngTotal Mod 11 = 0 Or lngTotal Mod 11 = 6 Then
fValidateBankAccount = True
End If
End Select
Case 9
lngTotal = CLng(strArrayAccount(0)) * 9 + _
CLng(strArrayAccount(1)) * 8 + _
CLng(strArrayAccount(2)) * 7 + _
CLng(strArrayAccount(3)) * 6 + _
CLng(strArrayAccount(4)) * 5 + _
CLng(strArrayAccount(5)) * 4 + _
CLng(strArrayAccount(6)) * 3 + _
CLng(strArrayAccount(7)) * 2 + _
CLng(strArrayAccount(8)) * 1
If lngTotal Mod 10 = 0 Then
fValidateBankAccount = True
End If
Case 22
lngTotal = CLng(strArrayAccount(0)) * 3 + _
CLng(strArrayAccount(1)) * 2 + _
CLng(strArrayAccount(2)) * 7 + _
CLng(strArrayAccount(3)) * 6 + _
CLng(strArrayAccount(4)) * 5 + _
CLng(strArrayAccount(5)) * 4 + _
CLng(strArrayAccount(6)) * 3 + _
CLng(strArrayAccount(7)) * 2
If 11 - (lngTotal Mod 11) = CLng(strArrayAccount(8)) Then
fValidateBankAccount = True
End If
Case 46
lngTotal = CLng(strArrayBranch(0)) * 9 + _
CLng(strArrayBranch(1)) * 8 + _
CLng(strArrayBranch(2)) * 7 + _
CLng(strArrayAccount(0)) * 6 + _
CLng(strArrayAccount(1)) * 5 + _
CLng(strArrayAccount(2)) * 4 + _
CLng(strArrayAccount(3)) * 3 + _
CLng(strArrayAccount(4)) * 2 + _
CLng(strArrayAccount(5)) * 1
Select Case lngTotal Mod 11
Case 0
fValidateBankAccount = True
Case 2
Select Case strBranch
Case 154, 166, 178, 181, 183, 191, 192, 503, 505, 507, 515, 516, 527, 539
fValidateBankAccount = True
End Select
End Select
If fValidateBankAccount = False Then
lngTotal = CLng(strArrayAccount(0)) * 9 + _
CLng(strArrayAccount(1)) * 8 + _
CLng(strArrayAccount(2)) * 7 + _
CLng(strArrayAccount(3)) * 6 + _
CLng(strArrayAccount(4)) * 5 + _
CLng(strArrayAccount(5)) * 4 + _
CLng(strArrayAccount(6)) * 3 + _
CLng(strArrayAccount(7)) * 2 + _
CLng(strArrayAccount(8)) * 1
If lngTotal Mod 11 = 0 Then
fValidateBankAccount = True
Else
lngTotal = CLng(strArrayAccount(3)) * 6 + _
CLng(strArrayAccount(4)) * 5 + _
CLng(strArrayAccount(5)) * 4 + _
CLng(strArrayAccount(6)) * 3 + _
CLng(strArrayAccount(7)) * 2 + _
CLng(strArrayAccount(8)) * 1
If lngTotal Mod 11 = 0 Then
fValidateBankAccount = True
End If
End If
End If
Case 14
lngTotal = CLng(strArrayBranch(0)) * 9 + _
CLng(strArrayBranch(1)) * 8 + _
CLng(strArrayBranch(2)) * 7 + _
CLng(strArrayAccount(0)) * 6 + _
CLng(strArrayAccount(1)) * 5 + _
CLng(strArrayAccount(2)) * 4 + _
CLng(strArrayAccount(3)) * 3 + _
CLng(strArrayAccount(4)) * 2 + _
CLng(strArrayAccount(5)) * 1
Select Case lngTotal Mod 11
Case 0
fValidateBankAccount = True
Case 2
Select Case strBranch
Case 347, 361, 362, 363, 365, 385, 384
fValidateBankAccount = True
End Select
Case 4
Select Case strBranch
Case 361, 362, 363
fValidateBankAccount = True
End Select
End Select
If fValidateBankAccount = False Then
lngTotal = CLng(strArrayAccount(0)) * 9 + _
CLng(strArrayAccount(1)) * 8 + _
CLng(strArrayAccount(2)) * 7 + _
CLng(strArrayAccount(3)) * 6 + _
CLng(strArrayAccount(4)) * 5 + _
CLng(strArrayAccount(5)) * 4 + _
CLng(strArrayAccount(6)) * 3 + _
CLng(strArrayAccount(7)) * 2 + _
CLng(strArrayAccount(8)) * 1
If lngTotal Mod 11 = 0 Then
fValidateBankAccount = True
Else
lngTotal = CLng(strArrayAccount(3)) * 6 + _
CLng(strArrayAccount(4)) * 5 + _
CLng(strArrayAccount(5)) * 4 + _
CLng(strArrayAccount(6)) * 3 + _
CLng(strArrayAccount(7)) * 2 + _
CLng(strArrayAccount(8)) * 1
If lngTotal Mod 11 = 0 Then
fValidateBankAccount = True
End If
End If
End If
End Select
End Function