a=0if a>0 then  dim c as classA
  set c = new classAend ifset c=nothing这段语句运行会不会出错?

解决方案 »

  1.   

        Dim o As Object
        If 1 = 0 Then
            Dim o As Object
        End If
        Set o = Nothing
    这样写的时候就看出来了,变量不能重复定义,可以看出定义在if里面和外面一样的。又set o = nothing仅仅是释放引用计数,当且仅当引用计数变为0时卸载对象。
    由于o的引用计数本来就是0,所以不会引发卸载。
      

  2.   

    a=0if a>0 then'上一句是a=0,所以这段代码不会执行  dim c as classA
      set c = new classAend ifset c=nothing'仅有可能执行这句,如果C没赋值,这句也是多余的
      

  3.   

    问题是c在if语句内声明,为什么set c= nothing 不会出错?
      

  4.   

    不会。Set C = Nothing
    Set C = Nothing
    Set C = Nothing这样也不会。
      

  5.   

    和C语言不一样。
    C语言有代码块概念,比如 { int i; } i = 3; // Error
    VB没有。
      

  6.   


    a=0if a>0 then  dim c as classAend if  set c = new classA
    这样会出错不?