【VFP】一段程序,那部分复制出来能当独立的身份证核查程序
程序如下,说明下,运行这个已经可以核查身份证校验码对错,但是一个文本超过100多个的时候,运行会出错,我在想是不是因为这个文本的另个程序模块有300限制而引起的?
这个程序do一下,直接可以把开户清单.xls(姓名,身份证号)里的身份证号核查并产生一个适合的开户txt文本。因为系统要求,文本里要求数量限制是不能超过300。
set safe off
set talk off
set proc to chd
pkhj='331082002'
use dfgz1 in 1
use newhead in 2
USE newbody IN 3
USE sfzherror IN 4
SELECT sfzherror
ZAP
SELECT dfgz1
zap
appe from 开户清单.xls type xl8
dele for allt(name)=="" or chrtran(name,' ','')=="姓名" or ALLTRIM(sfzh)==''
pack
*去掉身份证中误输入的TAB字符
REPLACE sfzh WITH CHRTRAN(sfzh,'','') all
COUNT TO totnew
newn=CEILING(totnew/300)
FOR cou=1 TO newn
*文件头
SELECT dfgz1
sum gze to hjgze FOR RECNO()<=300*cou AND RECNO()>300*(cou-1)
IF cou=newn
totn=totnew-300*(newn-1)
ELSE
totn=300
ENDIF
sele newhead
zap
appe blank
ptot=allt(str(totn))
phjgze=allt(str(hjgze*100))
repl sxh with pkhj+subs(dtos(date()),3,6)+chd(3-LEN(ALLTRIM(STR(cou))))+ALLTRIM(STR(cou))+'|',;
jrzs with chd(8-len(ptot))+ptot+'|',zjyje with chd(16-len(phjgze))+phjgze+'|',;
zywsxf with '000000000000|',zylsxf with '000000000000|',sfwtfh with '00|',wbjglx with '00|',;
wbjgdm with '00000000000000|',dsffhdm with '000000000|',;
pth with '00000000000|',zy with space(10)+'|'
headfname='newhead'+ALLTRIM(STR(cou))+'.txt'
copy to &headfname type sdf
*文件体
sele newbody
zap
sele dfgz1
go 300*(cou-1)+1
nn=0
do whil !EOF() AND nn<300
nn=nn+1
pnn=allt(str(nn))
pname=chrtran(name,' ','')
pgze=allt(str(gze*100))
IF LEN(ALLTRIM(sfzh))=18
IF SUBSTR(ALLTRIM(sfzh),18,1)='x'
REPLACE sfzh WITH SUBSTR(ALLTRIM(sfzh),1,17)+'X'
ENDIF
ENDIF
psfzh=allt(sfzh)
*核查身份证
pcheck=checkidno(psfzh)
IF psfzh<>pcheck
SELECT sfzherror
APPEND BLANK
REPLACE name WITH pname,sfzh WITH psfzh,checkend WITH pcheck
ENDIF
sele newbody
appe blank
repl num with chd(8-len(pnn))+pnn+'|',name with pname+space(22-len(pname)),;
bz with '|01|',sfzh with psfzh+space(18-len(psfzh))+'|',gze with chd(12-len(pgze))+pgze+'|',;
fzjg with space(26)+'3456|'
sele dfgz1
skip
endd
sele newbody
bodyfname='newbody'+ALLTRIM(STR(cou))+'.txt'
copy to &bodyfname type sdf
*合并
newfname='new'+substr(dtos(date()),3,6)+ALLTRIM(STR(cou))+'.txt'
a=FILETOSTR("&headfname")
b=FILETOSTR("&bodyfname")
STRTOFILE(a+b,"&newfname")
ENDFOR
SELECT sfzherror
COUNT TO toterr
IF toterr<>0
COPY TO sfzherror.txt deli WITH tab
aa=FILETOSTR('sfzherror.txt')
aa=STRTRAN(aa,["],'')
STRTOFILE(aa,'sfzherror.txt')
ENDIF
clos all
*核对身份证函数
FUNCTION checkidno
PARAMETERS idnumber
LOCAL checknum,i,m,temp1,temp2,temp3
IF LEN(idnumber)=15 OR LEN(idnumber)=18
IF LEN(idnumber)=15
m=0
FOR i=1 TO 15
IF !ISDIGIT(SUBSTR(idnumber,i,1))
m=m+1
*含有非数字字符
ENDIF
ENDFOR
IF m=0
temp1=SUBSTR(idnumber,9,2)+'/'+SUBSTR(idnumber,11,2)+'/'+SUBSTR(idnumber,7,2)
IF EMPTY(CTOD(temp1))
idnumber='日期非法'
ENDIF
ELSE
idnumber='非纯数字'
ENDIF
ELSE
*18位身份证
m=0
FOR i=1 TO 17
IF !ISDIGIT(SUBSTR(idnumber,i,1))
m=m+1
*含非数字字符
ENDIF
ENDFOR
IF m=0
temp1=SUBSTR(idnumber,11,2)+'/'+SUBSTR(idnumber,13,2)+'/'+SUBSTR(idnumber,7,4)
IF EMPTY(CTOD(temp1))
idnumber='日期非法'
ELSE
temp2=val(subs(idnumber,1,1))*7+val(subs(idnumber,2,1))*9+val(subs(idnumber,3,1))*10;
+val(subs(idnumber,4,1))*5+val(subs(idnumber,5,1))*8+val(subs(idnumber,6,1))*4;
+val(subs(idnumber,7,1))*2+val(subs(idnumber,8,1))*1+val(subs(idnumber,9,1))*6;
+val(subs(idnumber,10,1))*3+val(subs(idnumber,11,1))*7+val(subs(idnumber,12,1))*9;
+val(subs(idnumber,13,1))*10+val(subs(idnumber,14,1))*5+val(subs(idnumber,15,1))*8;
+val(subs(idnumber,16,1))*4+val(subs(idnumber,17,1))*2
temp3=temp2%11
DO CASE
CASE temp3=0
checknum='1'
CASE temp3=1
checknum='0'
CASE temp3=2
checknum='X'
CASE temp3=3
checknum='9'
CASE temp3=4
checknum='8'
CASE temp3=5
checknum='7'
CASE temp3=6
checknum='6'
CASE temp3=7
checknum='5'
CASE temp3=8
checknum='4'
CASE temp3=9
checknum='3'
CASE temp3=10
checknum='2'
ENDCASE
idnumber=SUBSTR(idnumber,1,17)+checknum
ENDIF
ELSE
idnumber='非纯数字'
ENDIF
ENDIF
ELSE
idnumber='长度不符'
ENDIF
RETURN idnumber
[解决办法]
请参考:
<关于身份证号码>
http://blog.csdn.net/apple_8180/archive/2006/07/19/941626.aspx