Changes from VB to VB.NET

In this article we discuss about what are the general changes from VB to VB.Net.

 

1)There are a number of general changes to be aware of when moving from VB to VB.NET.among them are topics such as the removal of default properties,subs and functions requiring parentheses, byval being the default method for passing parameters,and changes to the logical operators.

 

2)Boolean expression changes:*andalso,or else are new keywords in VB.NET:

Dim X as integer

Dim y as integer

X=1

Y=0

If X=2 and also Y=5/Y then this code does not cause an error;instead because X is not equal to 2,VB.NET does not even examine the second condition.

 

3)You can now initialize your variables when you declare them.you could not do this in VB6.

Ex:Dim X as integer=5

 

4)Another significant,and much-requested,change is that of declaring multiple vari-ables,and what data type they assume,on one line.for example,you might have the following line:

Dim X,Y as integer as you’re probably aware,in VB6,Y would be an integer data type,but X would be a variant.in VB.NET,this has changed,so both X and Y are integers.

 

5)The default way to pass parameters in VB has always been by reference(byRef).in VB.NET it is ByVal.

 

6)Param Arrays are now passed by val a parameter array,or paramArrray,is used when you do not know how many values you will pass into a procedure.a paramArray allows for an unlimited number of arguments.a parameter array automatically sizes to hold the number of elements you are passing in.a procedure can have only one paramarray,and it must be the last argument in the definition.the array must be one-dimensional and each element must be the same data type.however the default data type is object,which is what replaces the variant data type in VB.NET.in VB6,all the elements of a paramarray are always passed byref.this cannot be changed.in VB.NET,all the elements are passed byval.this cannot be changed.

 

7)Option strict is a new statement that specifically disallows any type conversions that would result in data loss.you can use only widening conversions;this means you could convert from an integer to a long, but you could not convert from a long to an integer.option strict also prevents conversions between numbers and strings.

 

8)All strings are Unicode:if you got tired of worrying about passing strings from VB to certain API calls that accepted either ANSI or Unicode strings,you will be happy to hear that all strings in VB.NET are Unicode.

 

9)The currency data type has been replaced:the “currency”data type has been replaced by the decimal data type.the decimal data type is a 12-byte signed integer that can have up to 28 digits to the right of the decimal place.

Vb6=private type customer

Name as string

Income as currency

End type

 

VB.NET=

Structure customer

Dim name as string

Dim income as decimal

End structure

 

10)Constructors and destructors are procedures that control the initialization and destruction of objects,respectively.

 

11)A namespace is a simple way to organize the objects in an assembly.

 

12)Garbage collection:garbage collection is now being handled by the runtime.

 

13)VB.NET refers to one or more classes compiled into a file as a class library,rather than a COM component.class libraries are compiled into an assembly,which often has a .DLL extension.you can use the classes from the class library much like you would the classes from a COM component:you instantiate the objects in the client application and then call properties and methods and respond to events.however, assemblies are not COM components;instead,they are .NET assemblies.

 

14)Typed data set:when selected,creates an instance of a dataset class already in your project.you can select from any dataset class defined using an XML schema(.xsd)file.this might be a dataset that you created or generated earlier,one that you are referencing from an XML web service,or one that is exposed by a namespace referenced in your project.name allows you to select or enter the name of a dataset class.you can use any dataset in the current project that has an XML schema(.xsd file)and a corresponding class file(.vb or.cs file).alternatively,you can enter the name of a dataset that you can enter the name of a dataset that you know will be available when the form or component is running.

 

15)Untyped data set:when selected,creates an instance of a new,untyped dataset in your form or component-that is,a dataset of type system.data.dataset.you would choose this option if you intended to allow the data adapter to create the schema when the dataset is filled or if you intended to add data tables and columns to the dataset programmatically.for more information on how the adapter can create a schema during while filling the dataset,see table mapping in data adapters.

 

Top ten tips for programming ASP.NET:

1)use visual studio.NET,but do not use default names for anything except trivial or non-referenced objects.

2)even if coding outside of visual studio.NET,use code-behind files for a performance benefit the first time a page is requested.

3)test for postback on page load.

4)use the stringbuilder class:strings are immutable in the .NET framework.this means that methods and operators,which appear to change the string,are actually returning a modified copy of the string.this has significant performance implications.when doing a lot of string manipulation,it is much better to use the string builder class

5)use server-side controls only when necessary.this flexibility comes at a cost,however.every server control consumes resources on the server.in addition,unless the view state is explicitly disabled either for the control,the page,or the application,the state of the control is contained within the view state’s hidden field,and passed over the wire with every postback.this can lead to significant.performance degradation.

6)to navigate to a URL without posting the form,use a hyperlink control;to post the form and then navigate,use a linkbutton.

7)comment your code

8)trace page execution using the trace methods and trace attribute in the page directive.

9)use stored procedures:Microsoft SQL server and other modern relational databases use SQL statements to define and process queries.when a SQL statement or set of SQL statements are submitted to the SQL server the statements are parsed,a query plan is created and optimized,and the query is executed.this takes time.

 

                        A stored procedure is a set of SQL statements that have been pre-parsed and pre-optimized by the query processor,and stored so they are ready for quick execution.stored procedures,often called sprocs,can be written to accept input parameters,allowing a single sproc to handle a wide range of specific queries.

 

                  Because sprocs are parsed in advance,and,more important for complex queries,have their query plans preoptimized,calling a sproc is much faster than executing the same SQL statements outside of a sproc.

 

10)use the .NET command prompt the .NET command line utilities are run from the command prompt window.in order for the command to execute however,it must reside in the current directory of the command prompt,or the PATH environment variable must be properlyset.

 

                             The .NET SDK installs a menu item in the start menu that opens up a command prompt window with the PATH properly set.to get to this,click on the start button,then programs>Microsoft visual studio NET>visual studio.NET tools>visual studio.NET

Command prompt.