超出数组范围 [英] out of bounds on array
问题描述
完成本教程,我似乎无法找到为什么我结束了运行我的数组的
。如果你有时间可以将它放入调试器中吗?
我没有一个asp页面。使用文本编辑器和我的打印语句
似乎没有透露错误。
Microsoft VBScript运行时错误''800a0009''
下标超出范围:''[数字:43]''
/Bp_1.asp,第80行
<% @ Language = VBscript%>
<%Option Explicit%>
< html>
< body>
<%
''_____________________________________________
''根据当前日期显示日历
''--------------------------------------------- ----
函数getMonthName(iMonth)
选择案例iMonth
案例1:
GetMonthName =" January"
案例2:
GetMonthName =" February"
案例3:
GetMonthName =" March"
案例4:
GetMonthName =" April"
案例5:
GetMonthName =" May"
案例6:
GetMonthName =" June"
案例7:
GetMonthName =" July"
案例8:
GetMonthName =" August"
案例9:
GetMonthName =" 9月>
案例10:
GetMonthName =" 10月>
案例11:
getMonthName =" November"
案例12:
getMonthName =" December"
case else
getMonthName = 在有效月份
结束选择
结束功能
Dim dbCurrentDate
dbCurrentDate =日期()
Dim aCalendarDays(42)
Dim iFirstWeekday
iFirstWeekDay =
DatePart(" w",DateSerial(Year(dbCurrentDate),Month(dbCurrentDate),1))
Dim iDaysInMonth
iDaysInMonth =
DatePart(" d",DateSerial(Year(dbCurrentDate),Month(dbCurre) ntDate)+1,1-1))
dim iLoop
iLoop = 1到iDaysInMonth
aCalendarDays(iLoop + iFirstWeekday - 1)= iLoop
next
Dim iColumns,iRows
iColumns = 7
iRows = 6 - Int((42 - (iFirstWeekDay + iDaysInMonth))/ 7)
%>
< ; table align = center border = 1 cellspacing = 1 width = 75%height = 75%
< th colspan = 7>
<%
Response.Write GetMonthName(Month(dbCurrentDate))
Response.Write"," &安培;年(dbCurrentDate)
%>
< / th>
<%
Dim iRowsLoop, iColumnsLoop
对于iRowsLoop = 1到iColumns
''创建一个新行
response.write"< tr>"
for iColumnsLoop = 1 to iColumns
''创建一个列
如果aCalendarDays((iRowsLoop-1)* 7 + iColumnsLoop)0则
''显示日期
Response.Write"< td valign = top align = right width ="" 14%"">" _
& aCalendarDays((iRowsLoop-1)* 7 + iColumnsLoop)_
& "< / td>"
else
''灰色单元格
response.write"< td bgcolor = grey> ;& nbsp;< / td>"
结束如果
next
''关闭行
response.write"< / tr>"
next
%>
< / table>
< br>< br>
你好再次
< /正文>
< / html>
working through this tutorial and I just can''t seem to find why I am over
running my array. If you have time can you drop this into your debugger?
I don''t have one for asp pages. Using a text editor and my print statements
don''t seem to be revealing the error.
Microsoft VBScript runtime error ''800a0009''
Subscript out of range: ''[number: 43]''
/Bp_1.asp, line 80
<%@ Language=VBscript %>
<% Option Explicit %>
<html>
<body>
<%
''_____________________________________________
'' Display a calendar based upon the current date
''-------------------------------------------------
Function getMonthName(iMonth)
Select Case iMonth
case 1:
GetMonthName = "January"
case 2:
GetMonthName = "February"
case 3:
GetMonthName = "March"
case 4:
GetMonthName = "April"
case 5:
GetMonthName = "May"
case 6:
GetMonthName = "June"
case 7:
GetMonthName = "July"
case 8:
GetMonthName = "August"
case 9:
GetMonthName = "September"
case 10:
GetMonthName = "October"
case 11:
getMonthName = "November"
case 12:
getMonthName = "December"
case else
getMonthName = "in valid month"
end select
end function
Dim dbCurrentDate
dbCurrentDate = Date()
Dim aCalendarDays(42)
Dim iFirstWeekday
iFirstWeekDay =
DatePart("w",DateSerial(Year(dbCurrentDate),Month( dbCurrentDate),1))
Dim iDaysInMonth
iDaysInMonth =
DatePart("d",DateSerial(Year(dbCurrentDate),Month( dbCurrentDate)+1, 1-1))
dim iLoop
For iLoop = 1 to iDaysInMonth
aCalendarDays(iLoop + iFirstWeekday - 1) = iLoop
next
Dim iColumns, iRows
iColumns = 7
iRows = 6 - Int((42 - (iFirstWeekDay + iDaysInMonth)) / 7)
%>
<table align=center border=1 cellspacing=1 width=75% height=75%
<th colspan=7>
<%
Response.Write GetMonthName(Month(dbCurrentDate))
Response.Write ", " & Year(dbCurrentDate)
%>
</th>
<%
Dim iRowsLoop, iColumnsLoop
For iRowsLoop = 1 to iColumns
''create a new row
response.write "<tr>"
for iColumnsLoop = 1 to iColumns
''create a column
if aCalendarDays((iRowsLoop-1)*7 + iColumnsLoop) 0 then
''dispaly the date
Response.Write "<td valign=top align=right width=""14%"">"_
& aCalendarDays((iRowsLoop-1)*7 + iColumnsLoop)_
& "</td>"
else
''gray out cell
response.write "<td bgcolor=gray> </td>"
end if
next
''close the row
response.write "</tr>"
next
%>
</table>
<br><br>
hello again
</body>
</html>
推荐答案
Kevin Raleigh写道:
Kevin Raleigh wrote:
通过本教程,我似乎无法找到为什么我在运行我的数组时获得
。如果你有时间可以将它放入你的
调试器中吗?
我没有一个用于asp页面。使用文本编辑器和我的打印
语句似乎没有揭示错误。
Microsoft VBScript运行时错误''800a0009''
下标超出范围:''[数字:43]''
/Bp_1.asp,第80行
working through this tutorial and I just can''t seem to find why I am
over running my array. If you have time can you drop this into your
debugger?
I don''t have one for asp pages. Using a text editor and my print
statements don''t seem to be revealing the error.
Microsoft VBScript runtime error ''800a0009''
Subscript out of range: ''[number: 43]''
/Bp_1.asp, line 80
< snip>
<snip>
>
函数getMonthName(iMonth)
>
Function getMonthName(iMonth)
FYI,vbscript有一个名为MonthName的函数,它执行这个函数
正在做的事情。您可以在此处获取vbscript文档:
http://tinyurl.com/7rk6
< snip>
FYI, vbscript has a function called MonthName that does what this function
is doing. You can get the vbscript documentation here:
http://tinyurl.com/7rk6
<snip>
iDaysInMonth =
DatePart(" d",DateSerial(Year(dbCurrentDate),Month(dbCurrentDate)+1,
1-1))
iDaysInMonth =
DatePart("d",DateSerial(Year(dbCurrentDate),Month( dbCurrentDate)+1,
1-1))
1-1?你的意思是0不是吗? ;-)
< snip>
1-1? You mean 0 don''t you? ;-)
<snip>
Dim iRowsLoop,iColumnsLoop
对于iRowsLoop = 1到iColumns
''创建一个新行
response.write"< tr>"
for iColumnsLoop = 1 to iColumns
''创建一个列
如果aCalendarDays((iRowsLoop-1)* 7 + iColumnsLoop)0然后
Dim iRowsLoop, iColumnsLoop
For iRowsLoop = 1 to iColumns
''create a new row
response.write "<tr>"
for iColumnsLoop = 1 to iColumns
''create a column
if aCalendarDays((iRowsLoop-1)*7 + iColumnsLoop) 0 then
这是你的问题:
iColumns包含7。你循环直到iRowLoops超过7.所以iRowLoops
可以包含7.(7-1)* 6 + 1 = 43,超过了这个
数组的上限。更改
对于iRowsLoop = 1到iColumns
到
对于iRowsLoop = 1到iColumns -1
-
Microsoft MVP - ASP / ASP.NET
请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我
不经常检查它。如果您必须离线回复,请删除
NO SPAM
Here is your problem:
iColumns contains 7. You are looping until iRowLoops exceeds 7. So iRowLoops
can contain 7. (7-1)*6 + 1 = 43, which exceeds the upper bound of this
array. Change
For iRowsLoop = 1 to iColumns
to
For iRowsLoop = 1 to iColumns-1
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don''t check it very often. If you must reply off-line, then remove the
"NO SPAM"
Bob Barrows [MVP]于2006年2月2日在
microsoft.public.inetserver.asp.general:
Bob Barrows [MVP] wrote on 02 sep 2006 in
microsoft.public.inetserver.asp.general:
>函数getMonthName(iMonth)
>Function getMonthName(iMonth)
FYI,vbscript有一个名为MonthName的函数来执行这个
函数正在做的事情。
FYI, vbscript has a function called MonthName that does what this
function is doing.
可能只有英文,Bob。
-
Evertjan。
荷兰。
(请将x''es更改为我的电子邮件地址中的点数)
Probably only in English, Bob.
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)
Evertjan。写道:
Evertjan. wrote:
Bob Barrows [MVP]于2006年2月2日在
microsoft.public.inetserver.asp.general写道:
Bob Barrows [MVP] wrote on 02 sep 2006 in
microsoft.public.inetserver.asp.general:
>>函数getMonthName(iMonth)
>>Function getMonthName(iMonth)
仅供参考,vbscript有一个名为MonthName的函数这就是这个功能正在做的事情。
FYI, vbscript has a function called MonthName that does what this
function is doing.
可能只有英文,鲍勃。
Probably only in English, Bob.
是的,但他的功能似乎是返回英文名字......
-
Microsoft MVP - ASP / ASP.NET
请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我
不经常检查它。如果您必须离线回复,请删除
无垃圾邮件
True, but his function seems to be returning English names ...
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don''t check it very often. If you must reply off-line, then remove the
"NO SPAM"
这篇关于超出数组范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!