Link to home
Create AccountLog in
Avatar of CLSTEAM
CLSTEAM

asked on

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!
SOLUTION
Avatar of hongjun
hongjun
Flag of Singapore image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of CLSTEAM
CLSTEAM

ASKER

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!
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of CLSTEAM

ASKER

Thanks guys!  Working now.  I wish I could have a red phone going straight to you guys!
Thanks for accepting.

<At the same time testing "Open for Discussion" new EE feature>