Option Strict issue

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have a vs 2003 project which I have just imported into vs 2005. Now I am
getting the "Option Strict On disallows operands of type Object for operator
'='. Use the 'Is' operator to test for object identity." error on the 'Case
"Main"' statement in the below code;

Select Case Row("Contact_Type")
Case "Main"
.....
End Select

What is the problem and how can I fix it?

Thanks

Regards
 
The Case "Main" is doing the equivalent of:

Case When Row("Contact_Type") = "Main"

In this case you are comparing an object to something using the = operator
and Option Strict does not allow that.

Row("Contact_Type") returns an object that you are expecting to conatain a
'boxed' string so you need to convert it to a string before you can compare
it to a string:

Select Case CType(Row("Contact_Type"), String)
Case "Main"
.....
End Select

should 'fix' it.
 
Hi

The reason is that Row("Contact_Type") returns an object. Cast is as an
integer and it will be OK:

Select Case Row("Contact_Type").ToString
Case "Main"
.....
End Select


--


HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
S2i web inc. (www.s2i.com)
http://emoreau.s2i.com/
 
Hi
The reason is that Row("Contact_Type") returns an object. Cast is as an
integer and it will be OK:

Select Case Row("Contact_Type").ToString
Case "Main"
.....
End Select


--

Hi

The reason is that Row("Contact_Type") returns an object. Cast it as a
string or use the objects .to string method when apropriate and it will be
OK

Select Case ctype(Row("Contact_Type",string)
Select Case cstr(Row("Contact_Type")
or just
Select Case Row("Contact_Type").ToString

AFAIK this problems should have also occured in previous versions of VS when
option strict is On
The bether code has Option explicit , and Options strict on above every code
block


Regards

Michel Posseth
 
In the VS 2005 IDE, you can set the Option Explicit, Option Strict, and
Option Compare options for all new projects. I strongly recommend you set
Explicit and Strict to "On". Set Option Compare to Text for compatibility
with VB6 or Binary for compatibility with the framework's System.String
class.

Mike Ober.
 
Back
Top