Data type returns with Strict On and Strict Off
The conventions for Option Strict On
and Option Strict Off
are described in Option Strict.
The return from the ObjProperty
function is an Object because it can return many different types of data. This data includes strings, numbers, dates and arrays of these types.
When you use CType
, ensure that you are converting to the correct data type. For example, if the ObjProperty
function returns an array of integers, you must convert it as such. An error occurs when you attempt to convert to a different data type.
To determine what exactly is returned, you can use the GetType
method on the returned object.
This syntax prints a message list that indicates the data type that was returned by the system.
Dim oItems As Object = ObjProperty("ITEMCODE.INGR.A", "", "", "*","")
MessageList("oItems variable is of the type: ", oItems.GetType().Name)
The name of the data type is the .Net name for the data type. See the MSDN article that lists the VB data types for more information: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vagrpdatatype.asp
To test for the data type, use the TypeOf
keyword.
Dim oItems As Object = ObjProperty("ITEMCODE.INGR.A", "", "", "*","")
If TypeOf oItems Is Object() Then
Dim oItemCds() As Object = CType(oItems, Object())
' processing logic...
End If