# Re: 统一编号

Posted by jo on October 18, 1998 at 02:00:51:

In Reply to: 统一编号 posted by 阿潭 on October 17, 1998 at 11:41:20:

: 请问如何CHECK统一编号是否正确

附上下列程式,

Function Chk_Ban(ID As String) As Integer '检查统一编号
Dim alpha_tbl As String
Dim c As String, cc As Integer
Dim i As Integer, sum As Integer, errflag As Integer

alpha_tbl = "12121241"

errflag = 0
If Len(ID) < 8 Then errflag = 1: GoTo Exit_Main
For i = 1 To 8
c = Mid$(ID, i, 1)
If i <= 8 Then
If c >= "0" And c <= "9" Then
cc = Val(Mid$(alpha_tbl, i, 1)) * Val(c)
If cc < 10 Then
sum = sum + cc
Else
Do
sum = sum + (cc Mod 10)
cc = cc \ 10
Loop Until cc <= 0
End If
Else
errflag = 1
End If
Else
If (Val(c) + (sum Mod 10)) Mod 10 <> 0 Or (c < "0" Or c > "9") Then errflag = 1
End If
If errflag = 1 Then Exit For
Next i

If sum Mod 10 <> 0 Then
errflag = 1
If Mid$(ID, 7, 1) = "7" And ((sum - 1) Mod 10 = 0) Then
errflag = 0
End If
End If

Exit_Main:
If errflag = 1 Then
Chk_Ban = 0
Else
Chk_Ban = 1
End If

End Function

Follow Ups: