我爱Aspx >> VB.Net >> 从VB6到VB.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
【我对这篇文章有话说?】
Chapter 3 Major VB.NET Changes..[05-20]
Chapter 4 Building Classes and..[05-20]
Chapter 3 Major VB.NET Changes..[05-20]
Chapter 3 Major VB.NET Changes..[05-20]
Chapter 2 Your First VB.NET(2)[05-20]
Chapter 2 Your First VB.NET(1)[05-20]
VB.NET 的新特点:变量,类型,数..[05-20]
VB.NET Samples(送给Blood等VB拥..[05-20]
HOW TO: Compute and Compare Ha..[05-20]
为什么选择VB.NET?(转贴)[05-20]
ReDim Preserve 執行效能上的陷阱..[05-20]
Chapter 3 Major VB.NET Changes..[05-20]
Chapter 4 Building Classes and..[05-20]
Chapter 3 Major VB.NET Changes..[05-20]
Chapter 3 Major VB.NET Changes..[05-20]
Chapter 2 Your First VB.NET(2)[05-20]
Chapter 2 Your First VB.NET(1)[05-20]
VB.NET 的新特点:变量,类型,数..[05-20]
VB.NET Samples(送给Blood等VB拥..[05-20]
HOW TO: Compute and Compare Ha..[05-20]