以下以原文程序来做一个分析,代码 :
set rs3=server.CreateObject("adodb.recordset")
 rs3.open "select id,wh from fgk order by len(wh) desc",conn,1,1  //取出数据
 while not rs3.eof
   title=rs3("wh")
   id=rs3("id")
 if instr(content,title)<>0 then   //查找tilel的内容是否存在于content中
  position=instr(content,title)-2
  if mid(content,position,1)<>"3" then //目的实现判断一下前面是否已经替换了,这样可以避免短标题的内容重复替                                                                     //换,如果已经替换则无需替换
   title1="<a href='law_detail.asp?id="&id&"'><font color=red size=3>"&title&"</font></a>"
   content=replace(content,title,title1)
  end if
 end if   
然后实行这段代码,但总会出现错误:无效的过程调用或参数: 'mid' ,自己分析了一下是不是mid这个函数的功能使用是不是存在问题,仔细查了一遍文档并没有找到任何不妥的地方,然后在if的判断语句后面加入一个输出语句,看错误出在哪里,
if instr(content,title)<>0 then   //查找tilel的内容是否存在于content中
  position=instr(content,title)-2
  response.write mid(content,position,1)
  if mid(content,position,1)<>"3" then //目的实现判断一下前面是否已经替换了,这样可以避免短标题的内容重复替                                                                     //换,如果已经替换则无需替换
   title1="<a href='law_detail.asp?id="&id&"'><font color=red size=3>"&title&"</font></a>"
   content=replace(content,title,title1)
  end if
再次运行,发现正常输出几行后再次出现这个错误:无效的过程调用或参数: 'mid'
既然前面可以正常输出,说明程序是没有问题的,有问题只能存在于内容本身,然后发现如果title为空的话,
if instr(content,title)<>0 then 这个条件是成立的,但这个时候 position=instr(content,title)-2 中的position可能
为负数,这样就直接导致mid(content,position,1)出错,因为在mid中position最小应该为0,于是在增加了一个判断条件,如下
  if mid(content,position,1)<>"3" and   title<>"" then
再次运行程序,问题解决