Use Option Explicit or Strict in Visual Basic


Early binding provides much better performance than late binding. To ensure that only early binding is used, always include the Option Explicit statement in code to force variables to be pre-declared. By default, ASP.NET pages are automatically compiled with the equivalent to Option Explicit set.

Also, always specify a data type for variables when they are declared. This provides strong typing of variables for best performance. For example, use:

  Dim intThis As Integer  

Rather than:

  Dim intThis  

As a comparison, failing to declare variable types and therefore forcing late binding can lead to performance that is about the same as using VBScript in ASP 3.0.

It's also worth using Option Strict where possible to enforce strict variable typing. This means that variables must be explicitly cast to the correct data type for each operation that requires a type conversion. Again, it can provide better performance, though it does involve more code and so may not always be appropriate. In ASP.NET, Strict compilation is enabled using:

  <%@ Page Language="VB" Strict="true" %>  



Professional ASP. NET 1.1
Professional ASP.NET MVC 1.0 (Wrox Programmer to Programmer)
ISBN: 0470384611
EAN: 2147483647
Year: 2006
Pages: 243

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net