"Strict" error

Results 1 to 2 of 2

Thread: "Strict" error

  1. #1
    Join Date
    Dec 1969

    Default "Strict" error

    I&#039;m getting the error, "Option Strict On prohibits operands of type Object for operator &#039;&&#039;." when I have Strict="True". But, I can&#039;t seem to figure out what&#039;s causing the problem. Here&#039;s the code:<BR><BR>[code language="vb.net"]<BR>Cmd = New OleDBCommand(SQL,Conn)<BR>RS=Cmd.ExecuteReader()<B R>if RS.Read() then<BR> RecCount.Text = "&#060;b&#062;" & RS("Cnt").ToString() & " Record" & iif(RS("Cnt").ToString() = "1","","s") & "&#060;/b&#062;" &#039; ERROR HERE<BR>end if<BR>[/code]<BR><BR>Any idea what might be causing the problem?<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default IIF always returns OBJECT...

    ...because it&#039;s perfectly legit to do something like<BR> IIF ( foo, new DateTime(), #3/14/2002# )<BR>etc.<BR><BR>So you have to cast the result of the IIF to a string.<BR><BR>CSTR( iif(RS("Cnt").ToString() = "1","","s") )<BR><BR>I know it seems silly, but that&#039;s the price you pay for the nice flexibility of IIF.<BR><BR>BY THE WAY: *CONGRATULATIONS* for using OPTION STRICT ON! 80% of the silly mistakes that happen with VB happend because people omit that.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts