Option Explicit On Programming Tips and Gotchas (Verizon web hosting)

Option Explicit On Programming Tips and Gotchas It is considered good programming practice to always use the OptionExplicit statement. The following example shows why: 1: Dim iVariable As Integer 2: iVariable = 100 3: iVariable = iVariable + 50 4: MsgBox iVariable In this code snippet, an integer variable, iVariable, has been declared. However, because the name of the variable has been mistyped in line 3, the message box shows its value as only 50 instead of 150. This is because iVarable is assumed to be an undeclared variable whose value is 0. If the OptionExplicit statement had been used, the code would not have compiled, and iVarable would have been highlighted as the cause. For an ASP.NET page, you use the @PAGE directive rather than OptionExplicit to require variable declaration. Its syntax is: <%@ Page Language="VB" Explicit=true|false %> By default, Explicit is true in ASP.NET pages. You can also use the section of the WEB.Config file to require variable declaration for an entire virtual directory or ASP.NET application by adding an explicit attribute to the compliation section. Its syntax is: In both cases, true corresponds to OptionExplicitOn, and false corresponds to Option Explicit Off. Option Strict Statement Syntax Option Strict [On | Off] Description OptionStrict prevents VB from making any implicit data type conversions that are narrowing since narrowing conversions may involve data loss. For example: Dim lNum As Long = 2455622 Dim iNum As Integer = lNum converts a Long (whose value can range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807) to an Integer (whose value can range from 2,147,483,648 to 2,147,483,647). In this case, even though no data loss would result from the narrowing, Option
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services

Comments are closed.