title: Classic ASP sub procedure call in Response.Write
body: <p>I have a classic ASP question.</p>
  
  <p>Attempting to do this: the recordset is a simple list of years from 1995 to 2020; and i am trying to make 2010(current year) the default selection in the drop down.</p>
  
  <p>issue:  I trying to call a Sub proc in "Response.Write", but it keeps giving me this error:</p>
  
  <blockquote>
    <p>"Error '800a000d' Type mismatch: 'selectyear' "</p>
  </blockquote>
  
  <p>Below is the code, the Attempt 1 works with out any problem. But when i move that "if" logic to a sub procedure and call it in the Request.Write, it gives me the error. </p>
  
  <p>Can any one please explain why Attempt1 works and Attempt2 wouldnt. </p>
  
  <pre><code>' Attempt 1:
  
      rsYEAR.Open qYEAR, objconn, 0, 1 
      response.Write "&lt;tr&gt;&lt;td&gt;Year:&lt;/td&gt; &lt;td&gt; &lt;select name='theyear' style=""WIDTH: 67px""&gt;" 
      dim selyr
      while not rsYEAR.EOF
          if CINT(rsYEAR.fields("year")) = year(now) then
              selyr = "selected"
          else selyr = ""
          end if
  
          Response.Write"&lt;option value='" &amp; rsYEAR.fields("year") &amp; "' "&amp; selyr &amp;" &gt;"  &amp; cstr(rsYEAR.Fields("year"))
          rsYEAR.MoveNext
      wend
      response.Write "&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;"
      rsYEAR.Close
  
  
  ' Attempt 2: 
  
      rsYEAR.Open qYEAR, objconn, 0, 1 
      response.Write "&lt;tr&gt;&lt;td&gt;Year:&lt;/td&gt; &lt;td&gt; &lt;select name='theyear' style=""WIDTH: 67px""&gt;" 
      dim selyr2
      while not rsYEAR.EOF
  
          Response.Write "&lt;option value='" &amp; rsYEAR.fields("year") &amp; "' " &amp; cstr(selectyear(cint(rsYEAR.fields("year")))) &amp;" &gt;"  &amp; cstr(rsYEAR.Fields("year")) 
          rsYEAR.MoveNext
      wend
      response.Write "&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;"
  
      'close and clean up
      rsYEAR.Close
      set rsYEAR = nothing
  </code></pre>
  
  <p>I would greatly appreciate your response.
  thank you,
  Shiva</p>