Late binding problem

  • Thread starter Thread starter Earl
  • Start date Start date
E

Earl

Option Strict On gives me a late-binding exception for the following code.
Note that EmployeeList is a listarray populated with Employee objects and
one of the Employee properties is the EmployeeID.

If IsDBNull(EmpIdRet) = False Then
'error trying to compare object property ID to an Int32 variable
If EmpIdRet = EmployeeList.Item(intCounter).EmployeeID Then
cmbEmployee.Text = EmployeeList.Item(intCounter).ToString
End If
End If
 
It's really hard to say exactly how to fix the problem without seeing more
of the code and having some idea of where exactly the error is occurring.

However, it could be simply, as the error message says, that you have some
late binding data conversion going on. Normally in VB.NET you can simply
assign different datatypes to each other (in some cases) to have VB do an
implicit conversion. For example

Dim s as string
Dim i as integer
i = 132
s = i

Adding Option Strict On to the code above would cause an exception since it
prevents such implicit data conversions from happening. For this reason you
simply cannot use late binding in an application that uses Option Strict On.
The compiler has no way of knowing at compile time whether the types you are
assigning to and copying from are of the same data type and so you get this
error. To work around it do an Explicit data type conversion. If you search
in MSDN or your online help for "Type Conversion Functions" you'll find the
full list of conversions that you can use. These should solve your problem.

Hope that helps,

Pete



--
Peter Wright
Author of ADO.NET Novice To Pro, from Apress Inc.
www.petewright.org


_____________________________
 
Back
Top