Bank Account Number 11 Check

# Bank Account Number 11 Check

• Tuesday, April 24, 2007 11:24 AM

Account number: 73.61.60.221

• 7 *9 + 3 *8 + 6 *7 + 1 *6 + 6 *5 + 0 *4 + 2 *3 + 2 *2 + 1 *1 = 176.

Divide with 11 gives decimal: 00.

176 / 11 = 16,00

how can i make this calculation in a function?

thanks!

### All Replies

• Tuesday, April 24, 2007 12:15 PM

Here is the basic idea, but note you'll have to tidy it up to make it safe.

Public Function DoIt(accNo as string) as Decimal

Dim accNos() as string = accNo.Replace(".","").Split("")
Dim d as Decimal

For i as integer = 9 to 1 Step -1
d &= parseint(accNos((i-9)*(i-9))) * i
Next

Return d /11
End Function
• Tuesday, April 24, 2007 12:25 PM

thanks for your reply, but i get the following error before building:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

DoIt("58.22.55.235")

End Sub

Public Function DoIt(ByVal accNo As String) As Decimal

Dim accNos() As String = accNo.Replace(".", "").Split("")

Dim d As Decimal

For i As Integer = 9 To 1 Step -1

d &= parseint(accNos((i - 9) * (i - 9))) * i

Next

Return d / 11

End Function

Error 1 Name 'parseint' is not declared.

• Tuesday, April 24, 2007 12:57 PM

Public Function DoIt(ByVal accNo As String) As Double

accNo = accNo.Replace(".", "")

Dim d As Double

For i As Integer = 9 To 1 Step -1

Dim x As Integer = CInt(Math.Sqrt((i - 9) * (i - 9)))

d = d + CInt(Val(accNo(x))) * i

Next

Return d / 11

End Function
• Tuesday, April 24, 2007 1:16 PM

thanks it works!

im not very good at this but how do i check if the value has decimals ? if the returned value is not a round number(if it contains decimals) its a invalid account nummer

thanks for helping me!!!

• Tuesday, April 24, 2007 1:41 PM

In that case, I would recommend changing it to the following. There should be some more rigorous error checking, but assuming it's not for a bank or anything, then it should be OK...

Public Function IsValidAccNo(ByVal accNo As String) As Boolean

accNo = accNo.Replace(".", "")

Dim d As Double

For i As Integer = 9 To 1 Step -1

Dim x As Integer = CInt(Math.Sqrt((i - 9) * (i - 9)))

d = d + CInt(Val(accNo(x))) * i

Next

Return d Mod 11 = 0

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If IsValidAccNo("
73.61.60.221") Then
MsgBox("Valid!")
Else
MsgBox("Invalid!")
End If

End Sub

• Tuesday, April 24, 2007 1:46 PM

Another approach:

Code Snippet

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim S As String = TextBox1.Text

Dim N As Long = CLng(Replace(S, ".", ""))

Dim SN As Long = 0

For I As Int16 = 1 To 9

SN += I * (N Mod 10)

N = N \ 10

Next I

If (SN Mod 11) = 0 Then

TextBox2.Text = "Valid Account"

Else

TextBox2.Text = "Invalid Account"

End If

End Sub

• Tuesday, April 24, 2007 3:07 PM

Thank you very mutch!

It works great!