Syntax Changes In Vb

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Syntax Changes In Vb as PDF for free.

More details

  • Words: 824
  • Pages: 3
VB.Net Beta 2

10 Syntax Changes in VB.NET Beta 2 The long-awaited VB.NET Beta 2 has been released at last, so this week's column is devoted to a few of the many changes in syntax that this new version enforces. This isn't a complete list, of course, and I am pretty sure I am leaving out something important, but at least you can use this information to get familiar with the new beta in less time. 1) BitAnd, BitOr, BitXor, and BitNot are gone: Beta 1 used these operators to implement bit-wise operations, whereas the old And, Or, Xor, and Not, had become pure Boolean operators. After many complains from the VB community, they decided to restore things as they work in VB6: And, Or, Xor, and Not are again bit-wise operators, and the Bitxxx operators are gone. 2) The AndAlso and OrElse operators: These operators implement short-circuit evaluation in If and Do expressions (and in general, in all Boolean expressions that consist of multiple Boolean items). Consider this expression: If x > 0 AndAlso y ^ x < 1 Then 26 In this case VB doesn't evaluate the term (y ^ x) if (x > 0) happens to be False, because that wouldn't change the value of the expression. Similarly, in the following case Do While x = 0 OrElse y ^ 3 < x VB stops evaluating the expression if (x = 0) is True, because the entire expression is surely True. While I don't like the new AndAlso and OrElse, I think that these new names prevent VB developers from carelessly applying short-circuiting when they don't really mean to do so. Maybe the language is less elegant, but certainly there will be fewer mistakes when converting legacy VB6 code. 3) Value in DIM and REDIM is the UBound of the array: In Beta 1, the value passed to Dim and ReDim was the number of elements (as in C++ and C#), a detail that puzzled many die-hard VBers. In Beta 2 this value has the same meaning as under VB6. Because all VB.NET arrays are zero-based, it means that the array always has one more element than the number specified in the statement: Dim arr(10) As Integer ' this array has 11 elements 4) Equality must be performed with the Is operator:

SUNSAT The Perfect Team

VB.Net Beta 2 In Beta 1 you can check whether two object variables point to the same object instance using the = operator; in Beta 2 and the final version you must use the Is operator (as you do in VB6). 5) The Microsoft.VisualBasic.Compatibility.VB6 namespace has moved: This namespace contained all the functions that have a VB6 name, and was meant to assist VB developers in migrating their apps. In Beta 2 all these functions are in the less verbose Microsoft.VisualBasic namespace. If you have written VB.NET code that uses these functions, you should only modify the Imports statement. 6) Attributes now precede the item they refer to: In Beta 1, position of < > attributes preceded the _name_ of the item they refer to, which led to a rather weird syntax, as in: Class MyClass Fortunately, in Beta 2 and the final release, attributes will precede the item they refer to, making for a more readable syntax that is similar to C#'s: Class MyClass You can move the attribute to a line of its own for a syntax that resembles C# even more closely: _ Class MyClass 7) The Currency data type is gone: This data type isn't supported any longer and you should use Decimal instead. The Decimal type has a higher precision and larger valid range. 8) The ToString method is now locale-aware: All classes inherit the ToString method from System.Object (the mother of all objects in .NET), and usually override it so that it returns a textual representation of the object's value. For all the objects in the .NET framework, ToString returns a local-aware value now. For example, if the object has a numeric value, ToString will return the string representation of such a value, but will use different symbols for the decimal separator: a period in the US, a comma in most European countries. 9) Names of collection objects have changed: This change affects the name of many objects in the framework. In Beta 1 the convention for naming collection-like objects was to use the plural of the name (e.g. "Parameters",

SUNSAT The Perfect Team

VB.Net Beta 2 "Properties", etc.). In Beta 2 the convention has changed, and now these objects have a trailing "Collection" word (e.g. "ParameterCollection", "PropertyCollection"). You should use a similar naming convention in your own object hierarchies. 10) ADO.NET namespaces have changed: In Beta 1, ADO.NET had two important namespaces: System.Data.ADO for objects of the generic data provider, and System.Data.Sql for the more specific SQL Server provider. These namespaces have changed into System.Data.OleDb and System.Data.SqlClient, respectively.

SUNSAT The Perfect Team

Related Documents

Syntax Changes In Vb
November 2019 10
Syntax
May 2020 13
Vb
November 2019 60
Vb
November 2019 53
Vb
November 2019 51
Vb
November 2019 46