dim as 和set =他们有什么区别?
比如:
dim cn as new adodb.connection
set conn = new adobo.connection
同样是定义,他们有什么区别么?

解决方案 »

  1.   

    dim 是定义,set是创建?
      

  2.   

    有点类似于C语言的:
    char * p="12345";       char *p;
    p="12345";
      

  3.   

    Dim   obj   As   New   Class   在VB4-6中仅仅声明一个对象变量,并不创建对象,直到第一次引用这个对象(即操作它)时,才自动创建对象,而   
      Set   obj   =   New   Class   则立即创建对象,但是obj必须提前声明为Class型的变量,如:   
      Dim   obj   As   Class   
      两者都是前期绑定
      

  4.   

    dim cn as new adodb.connection
    等同于
    dim cn as adodb.connection
    set cn = new adodb.connection
      

  5.   

    前一个定义,后一个创建新的实例。有时候必须采用set =new
      

  6.   

    前一个定义,后一个创建新的实例。有时候必须采用set =new
      

  7.   

    采用 dim cn as new adodb.connection 的定义,VB 编译器会在所有调用变量的代码前面加上这样的工作:
      if cn is nothing then set cn = new adodb.connection
    所以通常不推荐使用 dim ... as new ...。下面的两段代码可以看出不同
    (一)
    dim cn as adodb.connection 
    debug.print cn is nothing
    set cn = new adodb.connection 
    debug.print cn is nothing
    set cn = nothing
    debug.print cn is nothing
    (二)
    dim cn as new adodb.connection 
    debug.print cn is nothing
    'set cn = new adodb.connection 
    'debug.print cn is nothing
    set cn = nothing
    debug.print cn is nothing