日期:2009-02-10  浏览次数:20378 次

Using Parentheses with Method Calls


In ASP, you could freely call methods on objects without using parentheses, as shown below:
Sub WriteData()   Response.Write "This is data"End SubWriteData

In ASP .NET, you must use parentheses with all of your calls, even for methods that do not take any parameters. Writing your code, as in the example below, allows it to function correctly in both ASP and ASP .NET.
Sub WriteData()   Response.Write("This is data")End SubCall WriteData()

ByVal Is Now the Default


In Visual Basic, all parameter arguments were, by default, passed by reference or ByRef. In Visual Basic .NET, this has changed so that all arguments are now passed by value or ByVal by default. If you still wish to have "ByRef" behavior, you must explicitly use the ByRef keyword in front of your parameters as follows:
Sub MyByRefSub (ByRef Value)   Value = 53;End Sub

This is an area where you really need to be careful. When you are moving your code over to ASP .NET, I suggest double and triple checking each parameter used in your method calls to ensure that this change is what you really want. I suspect you will need to change some of them.

No More Default Properties


The concept of default properties no longer exists in Visual Basic .NET. What this means is that if you have ASP code that relies on a default property that was provided by one of your objects, you will need to change this to explicitly reference the desired property, as shown in the following code:
'ASP Syntax (Implicit retrieval of Column Value property)Set Conn = Server.CreateObject("ADODB.Connection")Conn.Open("TestDB")Set RS = Conn.Execute("Select * from Products")Response.Write RS("Name")'ASP.NET Syntax (Explicit retrieval of Column Value property)Conn = Server.CreateObject("ADODB.Connection")Conn.Open("TestDB")RS = Conn.Execute("Select * from Products")Response.Write (RS("Name").Value)

Changes in Data Types


In Visual Basic .NET, Integer values are now 32 bits and Long types have become 64 bits.
Problems may arise when invoking methods on COM objects from ASP .NET or calling Microsoft® Win32® API calls inside your custom Visual Basic components. Pay special attention to the actual data types required to ensure you are passing in or casting your values correctly.

Structured Exception Handling


Although the familiar On Error Resume Next and On Error Goto error handling techniques are still allowed in Visual Basic .NET, they are not the best way to do things anymore. Visual Basic now has full-blown structured exception handing using the Try, Catch, and Finally keywords. If possible, you should move to this new model for error handling as it allows for a more powerful and consistent mechanism in dealing with your application errors.

COM-Related Changes


With the introduction of the .NET Framework and ASP .NET, COM really has not been changed at all. This does not mean, however, that you do not need to worry about COM objects and how they behave when you are using them from ASP .NET. There are a couple of fundamental things you need to be aware of.

Threading Model Changes


The ASP .NET threading model is the Multiple Threaded Apartment (MTA). What this means is that components that you are using that were created for the Single Threaded Apartment (STA) will no longer perform or function reliably without taking some extra precautions in ASP .NET. This includes, but is not limited to, all COM components that have been created using Visual Basi