?
Solved

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

Posted on 2007-10-05
6
Medium Priority
?
1,731 Views
Last Modified: 2011-09-20
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!
0
Comment
Question by:CLSTEAM
  • 3
  • 2
6 Comments
 
LVL 33

Assisted Solution

by:hongjun
hongjun earned 1600 total points
ID: 20022791
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
 
LVL 20

Assisted Solution

by:jitganguly
jitganguly earned 400 total points
ID: 20022796
Put Option Explicit    at the top
0
 

Author Comment

by:CLSTEAM
ID: 20022883
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
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
LVL 33

Accepted Solution

by:
hongjun earned 1600 total points
ID: 20022916
Declare the constant before you use it

Const adModeReadWrite = 3
0
 

Author Comment

by:CLSTEAM
ID: 20022962
Thanks guys!  Working now.  I wish I could have a red phone going straight to you guys!
0
 
LVL 33

Expert Comment

by:hongjun
ID: 20022967
Thanks for accepting.

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

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is an ISAPI filter?   •      It's an assembly (.dll file) that can add or change the way IIS works.   •      They can be enabled globally for your web server or on a site-by-site basis.   When the IIS server receives a request, enabling the ISAPI fi…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question