在C语言里,return语句之后,所有代码都不再执行了。但是vb函数好像不是这样的
    If i = 0 Then
        fun = 0
    End If
    fun = 2
这段代码永远只有一个结果。
vb函数返回之后,代码继续往下执行吗?我感觉好像还会执行。在返回之后,加上exit fuction吗?

解决方案 »

  1.   

    Function fun(i As Integer) As Integer
        If i = 0 Then
            fun = 0
            Exit Function
        End If
        fun = 1
    End Function
    这样写符合规范吗?
      

  2.   

    你倒个个儿不就行了
    Function fun(i As Integer) As Integer
      fun = 1
      If i = 0 Then
         fun = 0
      End If
    End Function
      

  3.   

    没啥规不规范,就该这么写的。如果是过程中间推出,用exit sub
      

  4.   

    应该这样写 你那样写当然只返回1了 Function fun(i As Integer) As Integer
      If i = 0 Then
      fun = 0
      else
      fun = 1
      end if
    End Function