当前位置:编程学习 > VB >>

vb关于Exit Function 放进for循环不起作用?

'代码 For i = Zzi - 1 To Zzi - Qishu Step -1 If i > 0 Then If GSYZ(ZziJg, Grid.TextMatrix(i, 1), Mtype, YZnum) Then DuiCuoSP = DuiCuoSP + 1 If nextZzi = 0 Then nextZzi = i End If Else Exit Function End If Next i If nextZzi = 0 Then nextZzi = i - 1 KqiP = Right(Grid.TextMatrix(nextZzi, 0), 3) & "〖" & Grid.TextMatrix(nextZzi, 1) & "〗" 下面我说一下调试时的错误 关键是 i=0了! 我希望当 i=0 时 Exit Function 退出函数,直接退出 因为 i=0 时不退出到下面就会发生错误 可是实际 当 i=0 时函数并没有退出 为什么呢
追问:这有什么本质的区别吗?像你这样和原来逻辑上一样的,我试试没有用,还是退不出发生错误
其他:放个断点,单步跟踪一下就行了。   '代码 修改
  For i = Zzi - 1 To Zzi - Qishu Step -1
          If i > 0 Then
                  If GSYZ(ZziJg, Grid.TextMatrix(i, 1), Mtype, YZnum) Then
                          DuiCuoSP = DuiCuoSP + 1
                          If nextZzi = 0 Then nextZzi = i
                  End If
          End If
 
          if i = 0 then        goto ex_fc   
  Next i

  If nextZzi = 0 Then nextZzi = i - 1

  KqiP = Right(Grid.TextMatrix(nextZzi, 0), 3)  & "〖" & Grid.TextMatrix(nextZzi, 1) & "〗"

  ……
  ex_fc:
  end Function
 
  强制的goto跳转,虽然现在不提倡,但是可以解决一些问题。
  你试试吧

上一个:VB程序平时怎么练习的
下一个:有了开罐之王开罐子有什么好处吗?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,