PC Review


Reply
Thread Tools Rate Thread

Option Strict issue

 
 
John
Guest
Posts: n/a
 
      15th Jan 2007
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


 
Reply With Quote
 
 
 
 
Stephany Young
Guest
Posts: n/a
 
      15th Jan 2007
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Eric Moreau
Guest
Posts: n/a
 
      15th Jan 2007
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Michel Posseth [MCP]
Guest
Posts: n/a
 
      15th Jan 2007
> 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" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> 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
>>

>
>



 
Reply With Quote
 
Michael D. Ober
Guest
Posts: n/a
 
      15th Jan 2007
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]" <(E-Mail Removed)> wrote in message
news:ekYq%(E-Mail Removed)...
>> 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" <(E-Mail Removed)> schreef in bericht
> news:%(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>>> 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
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Option Strict On/Off mconnolly4 Microsoft VB .NET 8 10th Sep 2007 01:04 PM
Is there a way to do this with Option Strict On? Chad Dokmanovich Microsoft ASP .NET 8 8th Feb 2007 04:14 PM
Option Strict On........ WilsonSmith Microsoft ASP .NET 1 30th Jul 2004 03:12 PM
Conversion issue with option strict John Microsoft VB .NET 5 13th Apr 2004 10:36 PM
option strict crain Microsoft VB .NET 7 26th Mar 2004 02:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:53 PM.