数据合并问题,如何判断一个来源档是空字节数的,不给予操作接下来合并其他的来源档呢?

 所属目录:Java   |   类型:技术问答   |   时间:2007-05-21
 问题:

如果  
  ati040032005-06-2922000003.txt  
  ati040042005-06-2922000005.txt  
  两个来源文档的文件为空,0kb。其他来源档是有正常数据的。  
  现在程序如果有来源档为空的,合并数据就会报错。如果都有正常数据是可以正常数据合并的。  
  请问下面程序如何修改,可以即使有个别来源档为0kb,也可以正常进行数据合并呢?谢谢  
   
  invdata   =   datapath   &   "invdata"   &   date   &   "("   &   left(t_time,   2)   &   mid(t_time,   4,   2)   &   ")"   &   ".txt"  
   
  for   i   =   1   to   9  
          if   dir(datapath   &   "*00000"   &   trim(str(i))   &   ".txt")   <>   ""   then  
                  bkdatafiles(i)   =   dir(datapath   &   "*00000"   &   trim(str(i))   &   ".txt")  
                  datafiles(i)   =   datapath   &   bkdatafiles(i)  
                  set   o_flst(i)   =   ofs.opentextfile(datafiles(i))  
          else  
                  bflag(i)   =   true  
          end   if  
  next   i  
  for   i   =   10   to   11  
          if   dir(datapath   &   "*0000"   &   trim(str(i))   &   ".txt")   <>   ""   then  
                  bkdatafiles(i)   =   dir(datapath   &   "*0000"   &   trim(str(i))   &   ".txt")  
                  datafiles(i)   =   datapath   &   bkdatafiles(i)  
                  set   o_flst(i)   =   ofs.opentextfile(datafiles(i))  
          end   if  
  next   i  
  open   mergeddata   for   output   as   #99  
  open   invdata   for   output   as   #98  
  while   not   o_flst(1).atendofstream  
          tmpstring   =   o_flst(1).readline  
          policyno   =   left(tmpstring,   12)  
          ownername   =   mid(tmpstring,   (linenumber(tmpstring,   3)   +   1),   (linenumber(tmpstring,   4)   -   linenumber(tmpstring,   3)   -   1))  
          poldata   =   mid(tmpstring,   (linenumber(tmpstring,   6)   +   1),   (linenumber(tmpstring,   7)   -   linenumber(tmpstring,   6)   -   1))  
   
          if   not   finddata(policyno)   then  
                  call   insertdata(policyno)  
          else  
                  i   =   msgbox("是否还需要继续操作合并保单?",   vbokcancel)  
                          if   (i   =   vbcancel)   then  
                                  close   #99  
                                  close   #98  
                                  ofs.deletefile   mergeddata  
                                  ofs.deletefile   invdata  
                                  msgbox   ("操作取消成功")  
                                  exit   sub  
                          end   if  
          end   if  
           
          print   #99,   "!$"   &   policyno  
          print   #99,   "%%prog:   c:\case\cathylife\cathylife.jdt"  
          print   #99,   "gb01|"   &   tmpstring  
          if   tmpstr(8)   <>   ""   then  
                  print   #99,   "gb08|"   &   tmpstr(8)  
          end   if  
          tmpstring   =   o_flst(8).readline  
          while   left(tmpstring,   12)   =   policyno  
                  print   #99,   "gb08|"   &   tmpstring  
                  if   not   o_flst(8).atendofstream   then  
                          tmpstring   =   o_flst(8).readline  
                  else  
                          tmpstring   =   ""  
                  end   if  
          wend  
          tmpstr(8)   =   tmpstring  
          if   tmpstr(2)   =   ""   then  
                  tmpstring   =   o_flst(2).readline  
          else  
                  tmpstring   =   tmpstr(2)  
          end   if  
          while   left(tmpstring,   12)   =   policyno  
                  print   #99,   "gb0"   &   trim(str(2))   &   "|"   &   tmpstring  
                  if   not   o_flst(2).atendofstream   then  
                          tmpstring   =   o_flst(2).readline  
                  else  
                          tmpstring   =   ""  
                  end   if  
          wend  
          if   tmpstring   <>   ""   then  
                  tmpstr(2)   =   tmpstring  
          end   if  
           
          if   bflag(3)   =   false   then  
                  j   =   1  
                  if   tmpstr(3)   <>   ""   then  
                          print   #99,   "gb0"   &   trim(str(i))   &   ","   &   tmpstr(i)  
                          tmparry(j)   =   tmpstr(3)  
                          j   =   j   +   1  
                  end   if  
                  tmpstring   =   o_flst(3).readline  
                  while   left(tmpstring,   12)   =   policyno  
                          print   #99,   "gb0"   &   trim(str(i))   &   ","   &   tmpstring  
                          tmparry(j)   =   tmpstring  
                          j   =   j   +   1  
                          if   not   o_flst(3).atendofstream   then  
                                  tmpstring   =   o_flst(3).readline  
                          else  
                                  tmpstring   =   ""  
                          end   if  
                  wend  
                  if   not   o_flst(3).atendofstream   then  
                          tmpstr(3)   =   ""  
                          tmpstr(3)   =   tmpstring  
                  end   if  
          end   if  
          for   n   =   1   to   j   -   2  
                  for   m   =   n   +   1   to   j   -   1  
                          tmparry2   =   split(tmparry(n),   "|")  
                          tmparry3   =   split(tmparry(m),   "|")  
                          if   val(tmparry2(1))   >   val(tmparry3(1))   then  
                                  tmparrystring   =   tmparry(n)  
                                  tmparry(n)   =   tmparry(m)  
                                  tmparry(m)   =   tmparrystring  
                          end   if  
                  next   m  
          next   n  
          for   n   =   1   to   j   -   1  
                  print   #99,   "gb03|"   &   tmparry(n)  
          next   n  
           
          for   i   =   5   to   4   step   -1  
                  if   bflag(i)   =   false   then  
                          if   tmpstr(i)   <>   ""   then  
                                  print   #99,   "gb0"   &   trim(str(i))   &   "|"   &   tmpstr(i)  
                          end   if  
                          tmpstring   =   o_flst(i).readline  
                          while   left(tmpstring,   12)   =   policyno  
                                  print   #99,   "gb0"   &   trim(str(i))   &   "|"   &   tmpstring  
                                  if   not   o_flst(i).atendofstream   then  
                                          tmpstring   =   o_flst(i).readline  
                                  else  
                                          tmpstring   =   ""  
                                  end   if  
                          wend  
                          if   tmpstring   <>   ""   then  
                                  tmpstr(i)   =   tmpstring  
                          end   if  
                  end   if  
          next   i  
          tmpstring   =   text2.text   &   "*."   &   policyno   &   ".*"  
          tmpstring   =   dir(tmpstring)  
          print   #99,   "gbim|"   &   text2.text   &   tmpstring  
          tmpstring   =   o_flst(11).readline  
          print   #99,   "gb11|"   &   tmpstring  
          if   bflag(6)   =   false   then  
                          if   tmpstr(6)   =   ""   then  
                                  tmpstring   =   o_flst(6).readline  
                          else  
                                  tmpstring   =   tmpstr(6)  
                          end   if  
                          while   left(tmpstring,   12)   =   policyno  
                                  print   #99,   "gb0"   &   trim(str(6))   &   "|"   &   tmpstring  
                                  if   not   o_flst(6).atendofstream   then  
                                          tmpstring   =   o_flst(6).readline  
                                  else  
                                          tmpstring   =   ""  
                                  end   if  
                          wend  
                          if   tmpstring   <>   ""   then  
                                  tmpstr(6)   =   tmpstring  
                          end   if  
          end   if  
          o_flst(10).close  
          set   o_flst(10)   =   ofs.opentextfile(datafiles(10))  
          while   not   o_flst(10).atendofstream  
                  tmpstring   =   o_flst(10).readline  
                  if   left(tmpstring,   12)   =   policyno   then  
                          print   #99,   "gb10|"   &   tmpstring  
                  end   if  
          wend  
          o_flst(7).close  
          set   o_flst(7)   =   ofs.opentextfile(datafiles(7))  
          while   not   o_flst(7).atendofstream  
                  tmpstring   =   o_flst(7).readline  
                  if   trim(tmpstring)   <>   ""   then  
                  premium   =   mid(tmpstring,   (linenumber(tmpstring,   11)   +   1),   (linenumber(tmpstring,   12)   -   linenumber(tmpstring,   11)   -   1))  
   
                  if   left(tmpstring,   12)   =   policyno   then  
                          print   #99,   "gb07|"   &   tmpstring  
                          print   #98,   policyno   &   "|"   &   ownername   &   "|"   &   premium  
                  end   if  
                  end   if  
          wend  
          o_flst(9).close  
          set   o_flst(9)   =   ofs.opentextfile(datafiles(9))  
          while   not   o_flst(9).atendofstream  
                  tmpstring   =   o_flst(9).readline  
                  if   left(tmpstring,   12)   =   policyno   then  
                          print   #99,   "gb09|"   &   tmpstring  
                  end   if  
          wend  
          print   #99,   "%%eoj"  
          tmpstring   =   ""  
          for   i   =   1   to   11  
                  tmpstr(i)   =   ""  
          next   i  
  wend  
  close   #99  
  close   #98  
   
  for   i   =   1   to   11  
          set   o_flst(i)   =   nothing  
  next   i  
  if   option1.enabled   =   true   then  
          if   text3.text   =   ""   then  
                  text3.text   =   "c:\case\cathylife\data\bak\"  
          end   if  
          for   i   =   1   to   11  
                  bkdatafiles(i)   =   text3.text   &   bkdatafiles(i)  
                  if   datafiles(i)   <>   ""   then  
                          if   ofs.fileexists(bkdatafiles(i))   then  
                                  ofs.deletefile   bkdatafiles(i)  
                          end   if  
                          ofs.movefile   datafiles(i),   bkdatafiles(i)  
                  end   if  
          next   i  
  else  
          for   i   =   1   to   11  
                  if   datafiles(i)   <>   ""   then  
                          ofs.deletefile   datafiles(i)  
                  end   if  
          next   i  
  end   if  
  set   ofs   =   nothing  
  msgbox   ("数据文件合并完成。")  
   
  plast:  
  end   sub  
   
 

· 网友精彩回答:

发表者:of123

dim   strfile   as   string  
   
  for   i   =   1   to   9  
  strfile   =   dir(datapath   &   "*00000"   &   trim(str(i))   &   ".txt")  
  if   strfile   >   ""   then  
  if   filelen(strfile)then  
    bkdatafiles(i)   =   strfile  
    datafiles(i)   =   datapath   &   bkdatafiles(i)  
    set   o_flst(i)   =   ofs.opentextfile(datafiles(i))  
  else  
    bflag(i)   =   true  
  end   if  
  else  
    bflag(i)   =   true  
  end   if  
  next   i  
 

.
处理 SSI 文件时出错
© 2006-2008 All Rights Reserved