上面代码有错误,提示如下: Microsoft VBScript 编译器错误 错误 '800a03ea' 语法错误 /111.asp,行 83 Function LYearDays(y)
时间: 2024-11-09 11:28:21 浏览: 17
asp,VBscript语法错误,史上最全最详细最精确第1/3页
从你提供的错误信息来看,问题出在 `LYearDays` 函数的定义上。VBScript 和 JavaScript 在语法上有很大的不同,而你提供的代码是用 JavaScript 编写的。如果你尝试将这段 JavaScript 代码直接放在 ASP(Active Server Pages)文件中运行,就会出现语法错误。
### 解决方案:
1. **使用正确的语言**:ASP 文件通常使用 VBScript 或 JScript(Microsoft 版本的 JavaScript)。你需要确定你是要用哪种语言,并相应地编写代码。
2. **转换代码**:如果需要在 ASP 中使用这段代码,可以将其转换为 VBScript。
### 转换示例(VBScript 版本):
```vb
<%
Function GetLunar(newDate)
Dim nyear, nmonth, nday, nwday, nhrs, nmin, nsec
Dim lmonth, lday, lleap
If IsNull(newDate) Or newDate = "" Then
Set newDate = Now()
Else
Set newDate = CDate(newDate)
End If
nyear = Year(newDate)
nmonth = Month(newDate)
nday = Day(newDate)
nwday = Weekday(newDate)
nhrs = Hour(newDate)
nmin = Minute(newDate)
nsec = Second(newDate)
Call GetLunarInternal()
Function Draw()
Dim s
s = nyear & "年" & nmonth & "月" & nday & "日 星期" & cweekday(nwday) & " " & shapetime(nhrs, nmin, nsec)
s = s & " 农历" & lmonth & "月" & lday
Draw = lmonth & "月" & lday
End Function
Sub NewTick()
If Day(newDate) <> nday Then
nyear = Year(newDate)
nmonth = Month(newDate)
nwday = Weekday(newDate)
nday = Day(newDate)
Call GetLunarInternal()
End If
nhrs = Hour(newDate)
nmin = Minute(newDate)
nsec = Second(newDate)
End Sub
Function cweekday(wday)
Dim hzWeek
hzWeek = Array("日", "一", "二", "三", "四", "五", "六", "日")
cweekday = hzWeek(wday - 1)
End Function
Function shapetime(vhrs, vmin, vsec)
If vsec <= 9 Then vsec = "0" & vsec
If vmin <= 9 Then vmin = "0" & vmin
If vhrs <= 9 Then vhrs = "0" & vhrs
shapetime = vhrs & ":" & vmin & ":" & vsec
End Function
' 农历函数开始
Dim lunarInfo
lunarInfo = Array(&H04BD8, &H04AE0, &H0A570, &H054D5, &H0D260, &H0D950, &H16554, &H056A0, &H09AD0, &H055D2, _
&H04AE0, &H0A5B6, &H0A4D0, &H0D250, &H1D255, &H0B540, &H0D6A0, &H0ADA2, &H095B0, &H14977, _
&H04970, &H0A4B0, &H0B4B5, &H06A50, &H06D40, &H1AB54, &H02B60, &H09570, &H052F2, &H04970, _
&H06566, &H0D4A0, &H0EA50, &H06E95, &H05AD0, &H02B60, &H186E3, &H092E0, &H1C8D7, &H0C950, _
&H0D4A0, &H1D8A6, &H0B550, &H056A0, &H1A5B4, &H025D0, &H092D0, &H0D2B2, &H0A950, &H0B557, _
&H06CA0, &H0B550, &H15355, &H04DA0, &H0A5B0, &H14573, &H052B0, &H0A9A8, &H0E950, &H06AA0, _
&H0AEA6, &H0AB50, &H04B60, &H0AAE4, &H0A570, &H05260, &H0F263, &H0D950, &H05B57, &H056A0, _
&H096D0, &H04DD5, &H04AD0, &H0A4D0, &H0D4D4, &H0D250, &H0D558, &H0B540, &H0B6A0, &H195A6, _
&H095B0, &H049B0, &H0A974, &H0A4B0, &H0B27A, &H06A50, &H06D40, &H0AF46, &H0AB60, &H09570, _
&H04AF5, &H04970, &H064B0, &H074A3, &H0EA50, &H06B58, &H05AC0, &H0AB60, &H096D5, &H092E0, _
&H0C960, &H0D954, &H0D4A0, &H0DA50, &H07552, &H056A0, &H0ABB7, &H025D0, &H092D0, &H0CAB5, _
&H0A950, &H0B4A0, &H0BAA4, &H0AD50, &H055D9, &H04BA0, &H0A5B0, &H15176, &H052B0, &H0A930, _
&H07954, &H06AA0, &H0AD50, &H05B52, &H04B60, &H0A6E6, &H0A4E0, &H0D260, &H0EA65, &H0D530, _
&H05AA0, &H076A3, &H096D0, &H04BD7, &H04AD0, &H0A4D0, &H1D0B6, &H0D250, &H0D520, &H0DD45, _
&H0B5A0, &H056D0, &H055B2, &H049B0, &H0A577, &H0A4B0, &H0AA50, &H1B255, &H06D20, &H0ADA0, _
&H14B63)
Function LYearDays(y)
Dim i, sum
sum = 348
For i = &H8000 To &H8 Step -1
If (lunarInfo(y - 1900) And i) Then
sum = sum + 1
End If
Next
LYearDays = sum + LeapDays(y)
End Function
Function LeapDays(y)
If LeapMonth(y) Then
If (lunarInfo(y - 1900) And &H10000) Then
LeapDays = 30
Else
LeapDays = 29
End If
Else
LeapDays = 0
End If
End Function
Function LeapMonth(y)
LeapMonth = (lunarInfo(y - 1900) And &HF)
End Function
Function MonthDays(y, m)
If (lunarInfo(y - 1900) And (&H10000 Shr m)) Then
MonthDays = 30
Else
MonthDays = 29
End If
End Function
Class Lunar
Public year, month, day, isLeap
Private Sub Class_Initialize
Dim offset, temp, i, leap
offset = DateDiff("d", #1900-1-31#, newDate)
For i = 1900 To 2050
If offset <= 0 Then Exit For
temp = LYearDays(i)
offset = offset - temp
Next
If offset < 0 Then
offset = offset + temp
i = i - 1
End If
Me.year = i
leap = LeapMonth(Me.year)
Me.isLeap = False
For i = 1 To 13
If leap > 0 And i = (leap + 1) And Not Me.isLeap Then
i = i - 1
Me.isLeap = True
temp = LeapDays(Me.year)
Else
temp = MonthDays(Me.year, i)
End If
If Me.isLeap And i = (leap + 1) Then
Me.isLeap = False
End If
If offset <= 0 Then Exit For
offset = offset - temp
Next
If offset = 0 And leap > 0 And i = leap + 1 Then
If Me.isLeap Then
Me.isLeap = False
Else
Me.isLeap = True
i = i - 1
End If
End If
If offset < 0 Then
offset = offset + temp
i = i - 1
End If
Me.month = i
Me.day = offset + 1
End Sub
End Class
Dim nStr1, nStr2
nStr1 = Array("", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二")
nStr2 = Array("初", "十", "廿", "卅", "□")
Function GetcDay(d)
Select Case d
Case 10
GetcDay = "初十"
Case 20
GetcDay = "二十"
Case 30
GetcDay = "三十"
Case Else
GetcDay = nStr2(Fix(d / 10)) & nStr1(d Mod 10)
End Select
End Function
Function GetcMon(m)
If m = 1 Then
GetcMon = "正"
Else
GetcMon = nStr1(m)
End If
End Function
Sub GetLunarInternal()
Dim lObj
Set lObj = New Lunar
lmonth = GetcMon(lObj.month)
lday = GetcDay(lObj.day)
lleap = lObj.isLeap
If lleap Then
lmonth = "闰" & lmonth
End If
End Sub
GetLunar = Draw()
End Function
Response.Write(GetLunar("2023-11-03"))
%>
```
### 说明:
1. **日期处理**:VBScript 使用 `CDate` 和 `Now()` 函数来处理日期。
2. **数组和循环**:VBScript 的数组和循环与 JavaScript 类似,但有一些语法上的差异。
3. **类定义**:VBScript 支持类定义,但语法有所不同。
希望这能帮助你在 ASP 环境中正确运行农历转换功能。如果有任何其他问题,请随时提问!
阅读全文