469,647 Members | 1,789 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

Option Strict issue

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
Jan 14 '07 #1
4 5176
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.
"John" <Jo**@nospam.infovis.co.ukwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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

Jan 14 '07 #2
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/

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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

Jan 15 '07 #3
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
"Eric Moreau" <er*********************@videotron.caschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
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/

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>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


Jan 15 '07 #4
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.

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:ek***************@TK2MSFTNGP02.phx.gbl...
>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
"Eric Moreau" <er*********************@videotron.caschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
>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/

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>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



Jan 15 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Microsoft News | last post: by
12 posts views Thread by Simon Harris | last post: by
4 posts views Thread by Howard Kaikow | last post: by
1 post views Thread by Jerad Rose | last post: by
8 posts views Thread by Rory Becker | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.