主题:帮忙看看我的代码,是哪里出问题了?
这个网页就是显示天气用的,具体思路是,首先根据现在的时间判断应该显示哪个数据,然后从数据库里面提取数据,如果没有数据,就从天气预报网站读取新的数据,写入数据库,然后再显示读取到的新数据,不同的部分我已经用不同的颜色标出,现在问题出来了,运行的时候提示:
错误类型:
Microsoft VBScript 编译器错误 (0x800A0411)
名称重定义
/weather.asp, line 84, column 4
dim d(80)
---^
我仔细看过了,确实有量的d(80),一处是在
<!--#include file="getweather.asp" -->页面里面,
另外一处是在读取数据库的时候,
但是这两个数组已经用
if then
<!--#include file="getweather.asp" -->
else
d(80)
end if
这样的判断分开了,不可能同时出现,为什么还判断为错误呢
给我的感觉就是if的两种情况同时出现了,这怎么可能发生呢?
<!--#include file="getweather.asp" -->
这个页面没有问题,我测试过了,代码放在楼下。
代码如下:
<%
[color=008000]dim now_time_year,now_time_mouth,now_time_day,now_time_hour,now_time_minute,record_time_date
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = "(\d{4})-(\d{1,2})-(\d{1,2}).(\d{1,2}):(\d{1,2})" ' 设置模式。
regEx.IgnoreCase = True ' 设置区分大小写。
regEx.Global = True ' 搜索全部匹配。
Set Matches = regEx.Execute(now) ' 执行搜索。
For Each Match in Matches ' 循环遍历Matches集合。
now_time_year=Match.submatches(0)
now_time_month=Match.submatches(1)
now_time_day=CLng(Match.submatches(2))
now_time_hour=CLng(Match.submatches(3))
now_time_minute=CLng(Match.submatches(4))
Next
set regEx=nothing
'20:30以后
if now_time_hour>20 or (now_time_hour=20 and now_time_minute>=30) then
now_time_hour=20
record_time_date=cdate(now_time_year&"-"&now_time_month&"-"&now_time_day&" "&now_time_hour&":00:00")
end if
'8:30-12:30
if 8<now_time_hour<12 or (now_time_hour=8 and now_time_minute>=30) or (now_time_hour=12 and now_time_minute<30) then
now_time_hour=08
record_time_date=cdate(now_time_year&"-"&now_time_month&"-"&now_time_day&" "&now_time_hour&":00:00")
end if
'12:30-20:30
if 12<now_time_hour<20 or (now_time_hour=12 and now_time_minute>=30) or (now_time_hour=20 and now_time_minute<30) then
now_time_hour=12
record_time_date=cdate(now_time_year&"-"&now_time_month&"-"&now_time_day&" "&now_time_hour&":00:00")
end if
'8:30以前
if now_time_hour<8 or (now_time_hour=8 and now_time_minute<30) then
now_time_hour=20
now_time_day=now_time_day-1
record_time_date=cdate(now_time_year&"-"&now_time_month&"-"&now_time_day&" "&now_time_hour&":00:00")
end if [/color]
[color=000080]if Request.ServerVariables("Query_String")="" then
cityid=56778
else
cityid=request.QueryString("cityid")
end if[/color]
dsn="dsn=kmsc; uid=sa; pwd=810723;"
sql="select * from 短期天气预报 where cityid='"&cityid&"' and 日期1='"&record_time_date&"'"
set rs = Server.CreateObject("ADODB.recordset")
rs.open sql,dsn,1,1
[color=800000]if rs.eof or rs.bof then%>
<!--#include file="getweather.asp" -->[/color]
<%
[color=FF00FF]else
dim record_time_year,record_time_month,record_time_day,record_time_hour,record_time_minute
dim d(80)
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = "\d{4}-(\d{1,2})-(\d{1,2}).(\d{1,2})" ' 设置模式。
regEx.IgnoreCase = True ' 设置区分大小写。
regEx.Global = True ' 搜索全部匹配。
Set Matches = regEx.Execute(rs("日期1")) ' 执行搜索。
For Each Match in Matches ' 循环遍历Matches集合。
d(0)=Match.submatches(0)
d(1)=Match.submatches(1)
d(2)=Match.submatches(2)
Next
Set regEx = nothing
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = "\d{4}-(\d{1,2})-(\d{1,2}).(\d{1,2})" ' 设置模式。
regEx.IgnoreCase = True ' 设置区分大小写。
regEx.Global = True ' 搜索全部匹配。
Set Matches = regEx.Execute(rs("日期2")) ' 执行搜索。
For Each Match in Matches ' 循环遍历Matches集合。
d(3)=Match.submatches(0)
d(4)=Match.submatches(1)
d(5)=Match.submatches(2)
Next
Set regEx = nothing
for i=6 to 14
d(i)=rs(i-3)
next
d(16)=rs(12)
dim temp(15)
temp=split(trim(rs(13)),"|")
for i=20 to 35
d(i)=temp(i-20)
next
rs.close
set rs=nothing
end if
[/color]%>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2" height="36" background="images/top1bg.gif" class="smalltxt"> </td>
</tr>
<tr>
<td width="550" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="smalltxt">
<tr>
<td colspan="2" height="35" background="images/wth1.jpg" style="font-size:12px"> 今天是:<%=year(date)%>年<%=month(date)%>月<%=day(date)%>日 <%=WeekdayName(Weekday(Date))%> 现在的时间是:<%=hour(date)%>时<%=minute(date)%>分<%=second(date)%>秒
<a href="editweather.asp">编辑天气</a></td>
</tr>
<tr>
<td colspan="2" class="cross" style="font-size:20px; font-weight:bold; color:#60afe7">[color=FF0000]<%=d(19)%>[/color]</td>
</tr>
<tr>
<td class="leftb" width="33%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><%=d(19)%> (海拔:<%=d(18)%>)</td>
</tr>
<tr>
<td><img alt="<%=d(6)%>" src="/image/weather/big/<%=d(6)%>.gif" width="60" height="60"><%if d(7)<>"" then%><img alt="<%=d(7)%>" src="/image/weather/big/<%=d(7)%>.gif" width="60" height="60"><%end if%></td>
</tr>
<tr>
<td><%=d(8)%>℃~<%=d(9)%>℃</td>
</tr>
</table></td>
<td class="rightb" width="67%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><%=year(date)%>年<%=d(0)%>月<%=d(1)%>日<%=d(2)%>时至<%=year(date)%>年<%=d(3)%>月<%=d(4)%>日<%=d(5)%>时</td>
</tr>
<tr>
<td width="230"> 风力:<%=d(10)%></td>
<td> 日出:<%=d(11)%></td>
</tr>
<tr>
<td> 空气质量<%=d(12)%></td>
<td> 日落:<%=d(13)%></td>
</tr>
<tr>
<td> 污染物:<%=d(14)%></td>
<td> 东经:<%=d(15)%></td>
</tr>
<tr>
<td> 紫外线强度<%=d(16)%></td>
<td> 北纬:<%=d(17)%></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2" class="cross">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td width="85">项目</td>
<td width="28">指数</td>
<td>说明</td>
</tr>
<tr>
<td>舒适度指数:</td>
<td><%=d(20)%></td>
<td><%=d(28)%></td>
</tr>
<tr>
<td>穿衣指数:</td>
<td><%=d(21)%></td>
<td><%=d(29)%></td>
</tr>
<tr>
<td>晨练指数:</td>
<td><%=d(22)%></td>
<td><%=d(30)%></td>
</tr>
<tr>
<td>紫外线指数:</td>
<td><%=d(23)%></td>
<td><%=d(31)%></td>
</tr>
<tr>
<td>洗车指数:</td>
<td><%=d(24)%></td>
<td><%=d(32)%></td>
</tr>
<tr>
<td>感冒指数:</td>
<td><%=d(25)%></td>
<td><%=d(33)%></td>
</tr>
<tr>
<td>中暑指数:</td>
<td><%=d(26)%></td>
<td><%=d(34)%></td>
</tr>
<tr>
<td>晾晒指数:</td>
<td><%=d(27)%></td>
<td><%=d(35)%></td>
</tr>
</table> </td>
</tr>
<tr>
<td colspan="2" height="3" bgcolor="#60afe7" style="line-height:7px"> </td>
</tr>
</table>
</td>
<td width="250" valign="top"> </td>
</tr>
</table>
错误类型:
Microsoft VBScript 编译器错误 (0x800A0411)
名称重定义
/weather.asp, line 84, column 4
dim d(80)
---^
我仔细看过了,确实有量的d(80),一处是在
<!--#include file="getweather.asp" -->页面里面,
另外一处是在读取数据库的时候,
但是这两个数组已经用
if then
<!--#include file="getweather.asp" -->
else
d(80)
end if
这样的判断分开了,不可能同时出现,为什么还判断为错误呢
给我的感觉就是if的两种情况同时出现了,这怎么可能发生呢?
<!--#include file="getweather.asp" -->
这个页面没有问题,我测试过了,代码放在楼下。
代码如下:
<%
[color=008000]dim now_time_year,now_time_mouth,now_time_day,now_time_hour,now_time_minute,record_time_date
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = "(\d{4})-(\d{1,2})-(\d{1,2}).(\d{1,2}):(\d{1,2})" ' 设置模式。
regEx.IgnoreCase = True ' 设置区分大小写。
regEx.Global = True ' 搜索全部匹配。
Set Matches = regEx.Execute(now) ' 执行搜索。
For Each Match in Matches ' 循环遍历Matches集合。
now_time_year=Match.submatches(0)
now_time_month=Match.submatches(1)
now_time_day=CLng(Match.submatches(2))
now_time_hour=CLng(Match.submatches(3))
now_time_minute=CLng(Match.submatches(4))
Next
set regEx=nothing
'20:30以后
if now_time_hour>20 or (now_time_hour=20 and now_time_minute>=30) then
now_time_hour=20
record_time_date=cdate(now_time_year&"-"&now_time_month&"-"&now_time_day&" "&now_time_hour&":00:00")
end if
'8:30-12:30
if 8<now_time_hour<12 or (now_time_hour=8 and now_time_minute>=30) or (now_time_hour=12 and now_time_minute<30) then
now_time_hour=08
record_time_date=cdate(now_time_year&"-"&now_time_month&"-"&now_time_day&" "&now_time_hour&":00:00")
end if
'12:30-20:30
if 12<now_time_hour<20 or (now_time_hour=12 and now_time_minute>=30) or (now_time_hour=20 and now_time_minute<30) then
now_time_hour=12
record_time_date=cdate(now_time_year&"-"&now_time_month&"-"&now_time_day&" "&now_time_hour&":00:00")
end if
'8:30以前
if now_time_hour<8 or (now_time_hour=8 and now_time_minute<30) then
now_time_hour=20
now_time_day=now_time_day-1
record_time_date=cdate(now_time_year&"-"&now_time_month&"-"&now_time_day&" "&now_time_hour&":00:00")
end if [/color]
[color=000080]if Request.ServerVariables("Query_String")="" then
cityid=56778
else
cityid=request.QueryString("cityid")
end if[/color]
dsn="dsn=kmsc; uid=sa; pwd=810723;"
sql="select * from 短期天气预报 where cityid='"&cityid&"' and 日期1='"&record_time_date&"'"
set rs = Server.CreateObject("ADODB.recordset")
rs.open sql,dsn,1,1
[color=800000]if rs.eof or rs.bof then%>
<!--#include file="getweather.asp" -->[/color]
<%
[color=FF00FF]else
dim record_time_year,record_time_month,record_time_day,record_time_hour,record_time_minute
dim d(80)
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = "\d{4}-(\d{1,2})-(\d{1,2}).(\d{1,2})" ' 设置模式。
regEx.IgnoreCase = True ' 设置区分大小写。
regEx.Global = True ' 搜索全部匹配。
Set Matches = regEx.Execute(rs("日期1")) ' 执行搜索。
For Each Match in Matches ' 循环遍历Matches集合。
d(0)=Match.submatches(0)
d(1)=Match.submatches(1)
d(2)=Match.submatches(2)
Next
Set regEx = nothing
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = "\d{4}-(\d{1,2})-(\d{1,2}).(\d{1,2})" ' 设置模式。
regEx.IgnoreCase = True ' 设置区分大小写。
regEx.Global = True ' 搜索全部匹配。
Set Matches = regEx.Execute(rs("日期2")) ' 执行搜索。
For Each Match in Matches ' 循环遍历Matches集合。
d(3)=Match.submatches(0)
d(4)=Match.submatches(1)
d(5)=Match.submatches(2)
Next
Set regEx = nothing
for i=6 to 14
d(i)=rs(i-3)
next
d(16)=rs(12)
dim temp(15)
temp=split(trim(rs(13)),"|")
for i=20 to 35
d(i)=temp(i-20)
next
rs.close
set rs=nothing
end if
[/color]%>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2" height="36" background="images/top1bg.gif" class="smalltxt"> </td>
</tr>
<tr>
<td width="550" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="smalltxt">
<tr>
<td colspan="2" height="35" background="images/wth1.jpg" style="font-size:12px"> 今天是:<%=year(date)%>年<%=month(date)%>月<%=day(date)%>日 <%=WeekdayName(Weekday(Date))%> 现在的时间是:<%=hour(date)%>时<%=minute(date)%>分<%=second(date)%>秒
<a href="editweather.asp">编辑天气</a></td>
</tr>
<tr>
<td colspan="2" class="cross" style="font-size:20px; font-weight:bold; color:#60afe7">[color=FF0000]<%=d(19)%>[/color]</td>
</tr>
<tr>
<td class="leftb" width="33%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><%=d(19)%> (海拔:<%=d(18)%>)</td>
</tr>
<tr>
<td><img alt="<%=d(6)%>" src="/image/weather/big/<%=d(6)%>.gif" width="60" height="60"><%if d(7)<>"" then%><img alt="<%=d(7)%>" src="/image/weather/big/<%=d(7)%>.gif" width="60" height="60"><%end if%></td>
</tr>
<tr>
<td><%=d(8)%>℃~<%=d(9)%>℃</td>
</tr>
</table></td>
<td class="rightb" width="67%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><%=year(date)%>年<%=d(0)%>月<%=d(1)%>日<%=d(2)%>时至<%=year(date)%>年<%=d(3)%>月<%=d(4)%>日<%=d(5)%>时</td>
</tr>
<tr>
<td width="230"> 风力:<%=d(10)%></td>
<td> 日出:<%=d(11)%></td>
</tr>
<tr>
<td> 空气质量<%=d(12)%></td>
<td> 日落:<%=d(13)%></td>
</tr>
<tr>
<td> 污染物:<%=d(14)%></td>
<td> 东经:<%=d(15)%></td>
</tr>
<tr>
<td> 紫外线强度<%=d(16)%></td>
<td> 北纬:<%=d(17)%></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2" class="cross">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td width="85">项目</td>
<td width="28">指数</td>
<td>说明</td>
</tr>
<tr>
<td>舒适度指数:</td>
<td><%=d(20)%></td>
<td><%=d(28)%></td>
</tr>
<tr>
<td>穿衣指数:</td>
<td><%=d(21)%></td>
<td><%=d(29)%></td>
</tr>
<tr>
<td>晨练指数:</td>
<td><%=d(22)%></td>
<td><%=d(30)%></td>
</tr>
<tr>
<td>紫外线指数:</td>
<td><%=d(23)%></td>
<td><%=d(31)%></td>
</tr>
<tr>
<td>洗车指数:</td>
<td><%=d(24)%></td>
<td><%=d(32)%></td>
</tr>
<tr>
<td>感冒指数:</td>
<td><%=d(25)%></td>
<td><%=d(33)%></td>
</tr>
<tr>
<td>中暑指数:</td>
<td><%=d(26)%></td>
<td><%=d(34)%></td>
</tr>
<tr>
<td>晾晒指数:</td>
<td><%=d(27)%></td>
<td><%=d(35)%></td>
</tr>
</table> </td>
</tr>
<tr>
<td colspan="2" height="3" bgcolor="#60afe7" style="line-height:7px"> </td>
</tr>
</table>
</td>
<td width="250" valign="top"> </td>
</tr>
</table>