Home All Groups Group Topic Archive Search About
Author
14 Jan 2007 11:40 PM
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

Author
14 Jan 2007 11:50 PM
Stephany Young
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.


Show quoteHide quote
"John" <John@nospam.infovis.co.uk> wrote in message
news:%23QpPxVDOHHA.4172@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
>
Author
15 Jan 2007 12:50 AM
Eric Moreau
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/

Show quoteHide quote
"John" <John@nospam.infovis.co.uk> wrote in message
news:%23QpPxVDOHHA.4172@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
>
Author
15 Jan 2007 6:01 AM
Michel Posseth [MCP]
> 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


Show quoteHide quote
"Eric Moreau" <eric.moreau_N_O_S_P_***@videotron.ca> schreef in bericht
news:%23lFYd8DOHHA.2236@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" <John@nospam.infovis.co.uk> wrote in message
> news:%23QpPxVDOHHA.4172@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
>>
>
>
Author
15 Jan 2007 2:57 PM
Michael D. Ober
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.

Show quoteHide quote
"Michel Posseth [MCP]" <M***@posseth.com> wrote in message
news:ekYq%23pGOHHA.536@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" <eric.moreau_N_O_S_P_***@videotron.ca> schreef in bericht
> news:%23lFYd8DOHHA.2236@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" <John@nospam.infovis.co.uk> wrote in message
>> news:%23QpPxVDOHHA.4172@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
>>>
>>
>>
>
>