ASP Error: Microsoft VBScript compilation (0x800A0400) Expected statement

I get the following error:

Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/employees/test/calendar.asp, line 10

This is the code:

<%
  public dbConn, dbRs
  Set dbConn = Server.CreateObject("ADODB.Connection")
  Set dbRs = Server.CreateObject ("ADODB.Recordset")
  dbConn.Mode = adModeReadWrite
  dbConn.ConnectionString = "DSN=******;UID=css;PWD=*;"
  dbConn.Open

  ' force declaration of all variables
  Option Explicit         <--- THIS IS LINE 10
 
  Dim intYear, intMonth, intDay
  Dim intNumberOfDays, strDaysInMonths
  Dim strDate, strMonthName
  Dim strStyle, strTitle
  Dim strMethod, strURL  
  Dim strFirstDay, strLastDay, strCurrentDay
  Dim dtmPrev, dtmNext
  Dim X,Y,Z
 
 
 
  ' find out the URL of the page and the HTTP method used
  strMethod = UCase(Request.ServerVariables("REQUEST_METHOD"))
  strURL = LCase(Request.ServerVariables("URL"))
 
  ' if it's a GET then it's a regular browser request
  If strMethod="GET" Then
 
    ' use today's date
    intDay   = CInt(Day(Date()))
    intMonth = CInt(Month(Date()))
    intYear  = CInt(Year(Date()))
   
    strFirstDay = CStr(intMonth) & "-1-" & CStr(intYear)
    strDate  = CStr(intMonth) & "-" & CStr(intDay) & "-" & CStr(intYear)
   
  ' if it's a POST then it's a specific request
  Else
   
    ' get the submitted date
    intDay   = CInt(Day(Date()))
    intMonth = CInt(Request.Form("txtMonth"))
    intYear  = CInt(Request.Form("txtYear"))
   
    strFirstDay = CStr(intMonth) & "-1-" & CStr(intYear)
    strDate     = strFirstDay
   
  End If
 
  ' is a date in a leap year?
  Function IsLeapYearDate(dtmTestDate)
    IsLeapYearDate = False
    If IsDate(dtmTestDate) Then
      Dim dtmTempDate
      dtmTempDate = "1/31/" & Year(dtmTestDate)
      dtmTempDate = DateAdd("m", 1, dtmTempDate)
      If Day(dtmTempDate) = 29 Then IsLeapYearDate = True
    End If
  End Function

  ' create string of days in months
  If IsLeapYearDate("1/1/" & intYear) Then      
    strDaysInMonths = "312931303130313130313031"
  Else
    strDaysInMonths = "312831303130313130313031"
  End If
 
  ' get some date stuff
  strMonthName    = CStr(MonthName(intMonth))
  intNumberOfDays = CInt(Mid(strDaysInMonths,((intMonth-1)*2)+1,2))
  strLastDay      = CStr(intMonth) & "-" & intNumberOfDays & "-" & CStr(intYear)
 
  ' build the page title
  strTitle = "CSS Marketing Calendar for " & strMonthName & " " & intYear

  ' get the next and previous months for the menus
  dtmPrev = CDate(DateAdd("m", -1, strDate))
  dtmNext = CDate(DateAdd("m",  1, strDate))
 
%>
<html>
<head>
<title><%=strTitle%></title>
</head>

<body>

<h1 align="center"><%=strTitle%></h1>

<center>
  <table border="0" width="1235">
    <tr>
      <td align="left">
        <form action="<%=strURL%>" method="POST">
          <input type="hidden" name="txtMonth" value="<%=Month(dtmPrev)%>">
          <input type="hidden" name="txtYear" value="<%=Year(dtmPrev)%>">
          <input type="submit" style="width:150" value="View <%=MonthName(Month(dtmPrev))%>">
        </form>
      </td>
    <% If (intMonth <> Month(Date())) Or (intYear <> Year(Date())) Then %>
      <td align="center">
        <form action="<%=strURL%>" method="POST">
          <input type="hidden" name="txtMonth" value="<%=Month(Date())%>">
          <input type="hidden" name="txtYear" value="<%=Year(Date())%>">
          <input type="submit" style="width:150" value="View Current Month">
        </form>
      </td>
    <% End If %>
      <td align="right">
        <form action="<%=strURL%>" method="POST">
          <input type="hidden" name="txtMonth" value="<%=Month(dtmNext)%>">
          <input type="hidden" name="txtYear" value="<%=Year(dtmNext)%>">
          <input type="submit" style="width:150" value="View <%=MonthName(Month(dtmNext))%>">
        </form>
      </td>
    </tr>
  </table>
</center>


<table border="1" cellpadding="2" cellspacing="0" width="1235">
<tr>
<%
  ' print the weekday names
  For X = 1 to 7
    Response.Write "<th width=""14%"">" & WeekdayName(X) & "</th>" & vbCrLf
  Next
%>
</tr>
<tr>
<%  
  ' print empty table cells for the beginning days not in the current month
  If (Weekday(strFirstDay)-1) Then  
    For X = 1 to (Weekday(strFirstDay)-1)
      Response.Write "<td bgcolor='#dddddd'>&#xa0;</td>" & vbCrLf
    Next
  End If

  ' loop through the days in the current month
  For X = 1 to intNumberOfDays

    ' get the day we're working on
    strCurrentDay = CStr(intMonth) & "-" & X & "-" & CStr(intYear)
   
   
    ' start the table cell for a day
    Response.Write "<td id=""" & X & """ align=""left"" valign=""top"" height='75'>"
    Response.Write "<a href=viewday.asp?d="&X&"&m="&intMonth&"&y="&intYear&">" & X & "</a><br>" & vbCrLf
   
   


    ' end the table cell for a day
    Response.Write "</td>" & vbCrLf

    ' if the current day is then end of a week then output the end of the table row
    If (Weekday(strCurrentDay) = 7) And (strCurrentDay <> strLastDay) Then
      Response.Write "</tr>" & vbCrLf & "<tr>" & vbCrLf
    End If

  Next

  ' print empty table cells for the ending days not in the current month
  If (7-Weekday(strLastDay)) Then  
    For X = 1 to (7-Weekday(strLastDay))
      Response.Write "<td bgcolor='#dddddd' height='75'>&#xa0;</td>" & vbCrLf
    Next
  End If
%>
</tr>
</table>


</body>
</html>

I obtained this code from a microsoft website.  The code works fine without the first few lines before line 10.  The DB lines are the ones I successfully use on all the other webpages in the same server.  I don't know what the problem is here.  As you can see, I'm pretty new at ASP.  Thanks for the help!
CLSTEAMAsked:
Who is Participating?
 
hongjunCommented:
Declare the constant before you use it

Const adModeReadWrite = 3
0
 
hongjunCommented:
It has to be in the first line

<%
  ' force declaration of all variables
  Option Explicit

  public dbConn, dbRs
  Set dbConn = Server.CreateObject("ADODB.Connection")
  Set dbRs = Server.CreateObject ("ADODB.Recordset")
  dbConn.Mode = adModeReadWrite
  dbConn.ConnectionString = "DSN=******;UID=css;PWD=*;"
  dbConn.Open
 
  Dim intYear, intMonth, intDay
  Dim intNumberOfDays, strDaysInMonths
  Dim strDate, strMonthName
  Dim strStyle, strTitle
  Dim strMethod, strURL  
  Dim strFirstDay, strLastDay, strCurrentDay
  Dim dtmPrev, dtmNext
  Dim X,Y,Z
 
 
 
  ' find out the URL of the page and the HTTP method used
  strMethod = UCase(Request.ServerVariables("REQUEST_METHOD"))
  strURL = LCase(Request.ServerVariables("URL"))
 
  ' if it's a GET then it's a regular browser request
  If strMethod="GET" Then
 
    ' use today's date
    intDay   = CInt(Day(Date()))
    intMonth = CInt(Month(Date()))
    intYear  = CInt(Year(Date()))
   
    strFirstDay = CStr(intMonth) & "-1-" & CStr(intYear)
    strDate  = CStr(intMonth) & "-" & CStr(intDay) & "-" & CStr(intYear)
   
  ' if it's a POST then it's a specific request
  Else
   
    ' get the submitted date
    intDay   = CInt(Day(Date()))
    intMonth = CInt(Request.Form("txtMonth"))
    intYear  = CInt(Request.Form("txtYear"))
   
    strFirstDay = CStr(intMonth) & "-1-" & CStr(intYear)
    strDate     = strFirstDay
   
  End If
 
  ' is a date in a leap year?
  Function IsLeapYearDate(dtmTestDate)
    IsLeapYearDate = False
    If IsDate(dtmTestDate) Then
      Dim dtmTempDate
      dtmTempDate = "1/31/" & Year(dtmTestDate)
      dtmTempDate = DateAdd("m", 1, dtmTempDate)
      If Day(dtmTempDate) = 29 Then IsLeapYearDate = True
    End If
  End Function

  ' create string of days in months
  If IsLeapYearDate("1/1/" & intYear) Then      
    strDaysInMonths = "312931303130313130313031"
  Else
    strDaysInMonths = "312831303130313130313031"
  End If
 
  ' get some date stuff
  strMonthName    = CStr(MonthName(intMonth))
  intNumberOfDays = CInt(Mid(strDaysInMonths,((intMonth-1)*2)+1,2))
  strLastDay      = CStr(intMonth) & "-" & intNumberOfDays & "-" & CStr(intYear)
 
  ' build the page title
  strTitle = "CSS Marketing Calendar for " & strMonthName & " " & intYear

  ' get the next and previous months for the menus
  dtmPrev = CDate(DateAdd("m", -1, strDate))
  dtmNext = CDate(DateAdd("m",  1, strDate))
 
%>
<html>
<head>
<title><%=strTitle%></title>
</head>

<body>

<h1 align="center"><%=strTitle%></h1>

<center>
  <table border="0" width="1235">
    <tr>
      <td align="left">
        <form action="<%=strURL%>" method="POST">
          <input type="hidden" name="txtMonth" value="<%=Month(dtmPrev)%>">
          <input type="hidden" name="txtYear" value="<%=Year(dtmPrev)%>">
          <input type="submit" style="width:150" value="View <%=MonthName(Month(dtmPrev))%>">
        </form>
      </td>
    <% If (intMonth <> Month(Date())) Or (intYear <> Year(Date())) Then %>
      <td align="center">
        <form action="<%=strURL%>" method="POST">
          <input type="hidden" name="txtMonth" value="<%=Month(Date())%>">
          <input type="hidden" name="txtYear" value="<%=Year(Date())%>">
          <input type="submit" style="width:150" value="View Current Month">
        </form>
      </td>
    <% End If %>
      <td align="right">
        <form action="<%=strURL%>" method="POST">
          <input type="hidden" name="txtMonth" value="<%=Month(dtmNext)%>">
          <input type="hidden" name="txtYear" value="<%=Year(dtmNext)%>">
          <input type="submit" style="width:150" value="View <%=MonthName(Month(dtmNext))%>">
        </form>
      </td>
    </tr>
  </table>
</center>


<table border="1" cellpadding="2" cellspacing="0" width="1235">
<tr>
<%
  ' print the weekday names
  For X = 1 to 7
    Response.Write "<th width=""14%"">" & WeekdayName(X) & "</th>" & vbCrLf
  Next
%>
</tr>
<tr>
<%  
  ' print empty table cells for the beginning days not in the current month
  If (Weekday(strFirstDay)-1) Then  
    For X = 1 to (Weekday(strFirstDay)-1)
      Response.Write "<td bgcolor='#dddddd'>&#xa0;</td>" & vbCrLf
    Next
  End If

  ' loop through the days in the current month
  For X = 1 to intNumberOfDays

    ' get the day we're working on
    strCurrentDay = CStr(intMonth) & "-" & X & "-" & CStr(intYear)
   
   
    ' start the table cell for a day
    Response.Write "<td id=""" & X & """ align=""left"" valign=""top"" height='75'>"
    Response.Write "<a href=viewday.asp?d="&X&"&m="&intMonth&"&y="&intYear&">" & X & "</a><br>" & vbCrLf
   
   


    ' end the table cell for a day
    Response.Write "</td>" & vbCrLf

    ' if the current day is then end of a week then output the end of the table row
    If (Weekday(strCurrentDay) = 7) And (strCurrentDay <> strLastDay) Then
      Response.Write "</tr>" & vbCrLf & "<tr>" & vbCrLf
    End If

  Next

  ' print empty table cells for the ending days not in the current month
  If (7-Weekday(strLastDay)) Then  
    For X = 1 to (7-Weekday(strLastDay))
      Response.Write "<td bgcolor='#dddddd' height='75'>&#xa0;</td>" & vbCrLf
    Next
  End If
%>
</tr>
</table>


</body>
</html>
0
 
jitgangulyCommented:
Put Option Explicit    at the top
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
CLSTEAMAuthor Commented:
When I put Option Explicit at the top I get the following error:

Error Type:
Microsoft VBScript runtime (0x800A01F4)
Variable is undefined: 'adModeReadWrite'
/employees/test/calendar.asp, line 6

Thanks!
0
 
CLSTEAMAuthor Commented:
Thanks guys!  Working now.  I wish I could have a red phone going straight to you guys!
0
 
hongjunCommented:
Thanks for accepting.

<At the same time testing "Open for Discussion" new EE feature>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.