Function DvCosif(NrConta As String) As Integer

'CALCULA DV DO PLANO DE CONTAS COSIF

Dim i As Double, k As String

k = Mid$(Replace(CStr(NrConta), ".", ""), 1, 7)

k = IIf(Len(k) < 7, Replace(k & Space(7 - Len(k)), Space(1), 0, 1, 7 - Len(k)), k)

i = (CDbl(Mid(k, 7, 1)) * 3) + (CDbl(Mid(k, 6, 1)) * 7) + (CDbl(Mid(k, 5, 1)) * 1) + _

(CDbl(Mid(k, 4, 1)) * 3) + (CDbl(Mid(k, 3, 1)) * 7) + (CDbl(Mid(k, 2, 1)) * 1) + _

(CDbl(Mid(k, 1, 1)) * 3)

i = i Mod 10

DvCosif = IIf(i = 0, 0, 10 - i)

End Function