• 您的位置我爱Aspx >> VB.Net >> 从VB6到VB.NET的变化综述(转)
  • 从VB6到VB.NET的变化综述(转)

  • 作者:aspxer  来源:internet  日期:2007-5-20 14:01:38  关键字:.net
  • 变量范围

    考虑以下 VB6 代码:

    If x=y then

    Dim z as integer

    @# other code

    End If

    z=100 @#Outside of If ... Then block

    以上代码在VB6中运行得非常好,因为它没有模块级变量作用范围。模块级变量发生在其它高级编程语言中,如C++。在声明模块中定义的变量,如在 If ... Then模块中定义的变量,当这个声明模块结束时就会落在范围之外。这样一来,如果在其定义的If ... Then模块之外存取 z,在高级编程语言中就会导致一个错误。而VB.NET与VB6相反,它使用了模块层的变量范围。

    Set和Let声明

    在VB6中,你必须使用 Set声明为变量分配一个对象例示。出于默认属性的原因,这在VB6 中是必须的。要想告诉VB你想给对象本身指定一个变量(与对象的默认属性值相反),你就必须要使用Set关键字。例如,在 VB6中:

    Dim x as Variant

    Dim strName as string

    @#Assign the value of Text1.Text to StrName

    @#(Text is the default property of the textbox control in VB6)

    StrName=Text1

    @#Here we assign the actual Textbox object to the variable x

    @#Note that we use the Set keyword so VB knows we want to assign

    @#to x the object itself instead of the default property

    Set x=Text1

    我对这篇文章有话说?
  • 广告位招租,广告代号:content_468_15
  • 上一篇:给blood的礼物《A Programmers Introduction to Visual Basic.Net》
    下一篇:ReDim Preserve 執行效能上的陷阱(转)