Windows Phone Developers

Sunday, April 27, 2008

Implicit conversion from '' to ''

An expression or an assignment statement takes a value of one data type and converts it to another type. Because no conversion keyword is used, the conversion is implicit.


Implicit conversion from 'Object' to 'Microsoft.Office.Core.CommandBars' can be rectified using

CType(app.CommandBars, Microsoft.Office.Core.CommandBars)

Ctype returns the result of explicitly converting an expression to a specified data type, object, structure, class, or interface.

expression

Any valid expression. If the value of expression is outside the range allowed by typename, Visual Basic throws an exception.

typename

Any expression that is legal within an As clause in a Dim statement, that is, the name of any data type, object, structure, class, or interface.

CType is compiled inline, which means that the conversion code is part of the code that evaluates the expression. In some cases there is no call to a procedure to accomplish the conversion, which makes execution faster.

If no conversion is defined from expression to typename, for example from Integer to Date, Visual Basic displays a compile-time error message.

If a conversion fails at run time, the appropriate exception occurs. If a narrowing conversion fails, an OverflowException is the most common result. If the conversion is undefined, an InvalidCastException occurs. This can happen, for example, if expression is of type Object and its run-time type has no conversion to typename.

If the data type of expression or typename is a class or structure you have defined, you can define CType on that class or structure as a conversion operator. This makes CType act as an overloaded operator. If you do this, you can control the behavior of conversions to and from your class or structure, including what exceptions can be thrown.

Overloading

The CType operator can also be overloaded on a class or structure defined outside your code. If your code converts to or from such a class or structure, be sure you understand the behavior of its CType operator.

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005