OptionStrictonOptionExplicitOn option strict on

Option Stricton


Visual Basic.NET generally allows implicitconversions of any data type to any other data type. Data loss canoccur when the value of one data type is converted to a data typewith less precision or smaller capacity, however, a run-time errormessage will occur if data will be lost in such a conversion.Option Strict ensures compile-time notification of thesetypes of conversions so they may be avoided.

In addition to disallowing narrowing conversions, OptionStrict generates an error for late binding. An object islate bound when it is assigned to a variable that is declared to beof type Object.

NoteThecompiler default is Option Strict Off if do not specifyOption Strict in your code.

Example

This example demonstrates how the Option Strictstatement disallows late binding and conversions where data wouldbe lost.

Option Strict On   ' Force explicit variable declaration.Dim MyVar As Integer   ' Declare variables.Dim Obj As ObjectMyVar = 1000   ' Declared variable does not generate error.'Attempting to convert to an Integer generates an error.MyVar = 1234567890.987654321''Call Obj.Method1()   ' Late-bound call generates an error


Option Explicit On

Remarks


If used, the Option Explicit statement must appear in a file before any other source statements.
When Option Explicit appears in a file, you must explicitly declare all variables using the Dim, Private, Public, or ReDim statements. If you attempt to use an undeclared variable name, an error occurs at compile time.
If you don't use the Option Explicit statement, all undeclared variables are of Object type.
NoteUseOption Explicit to avoid incorrectly typing the name of anexisting variable or to avoid confusion in code where the scope ofthe variable is not clear. If you do not specify OptionExplicit in your code, the compiler default is OptionExplicit On.

Example


This example uses the Option Explicit statement to force explicit declaration of all variables. Attempting to use an undeclared variable causes an error at compile time. The Option Explicit statement is used at the module level only.
Option Explicit On   ' Force explicit variable declaration.Dim MyVar As Integer   ' Declare variable.MyInt = 10   ' Undeclared variable generates error.MyVar = 10   ' Declared variable does not generate error.

  

爱华网本文地址 » http://www.413yy.cn/a/25101015/243347.html

更多阅读

Howisitgoingon?(出差第三十六天) how s it going on

先说一件昨天的糗事。昨天一位印度兄弟走进办公室,对我说了一句“How is it going on ?”我一下蒙了,问我怎么样?到底是那件事情怎么样了?好像最近没有找他嘛!他看见我满脸的问号,又重复了一遍 “How is it goingon ?”我继续发懵。。。他

agree with ,agree to ,agree on 用法探究 agree的用法

agree with ,agree to ,agree on 用法探究。[观察分析]1. They agreed on the project at last.最后他们就这项工程达成了共识。2. I agree with you =I agree with what you said.我同意你的话。3. We agreed on a price for the c

36小时on call第1部粤语 oncall36小时2粤语版

On Call 36小时 01—在线播放—《On Call 36小时》—电视剧—优酷... 2012年2月14日-43分53秒On Call 36小时(2012)8.8地区:香港类型:剧情/言情/时装导演:潘嘉德主演:杨怡/马国明/罗仲谦一群未来准医生同历生老病死,与疾病日夜拼博,

Sql server Always On 读写分离配置方法 mssqlserver 读写分离

使用了Sqlserver 2012 Always on技术后,假如采用的配置是默认配置,会出现Primary server CPU很高的情况发生,比如默认配置如下:需要自定义来解决这个问题。我们先来看看上图中的这些选项的意义主角色中的连接允许所有连接 如果当前serve

声明:《OptionStrictonOptionExplicitOn option strict on》为网友一炮泯恩仇分享!如侵犯到您的合法权益请联系我们删除