473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

out of bounds on array

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>&nbsp;</td>"
end if
next

'close the row
response.write "</tr>"
next

%>

</table>

<br><br>
hello again
</body>
</html>


Sep 1 '06 #1
11 1806
Kevin Raleigh wrote:
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>
>
Function getMonthName(iMonth)
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))
1-1? You mean 0 don't you? ;-)

<snip>
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
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"
Sep 2 '06 #2
Bob Barrows [MVP] wrote on 02 sep 2006 in
microsoft.public.inetserver.asp.general:
>Function getMonthName(iMonth)

FYI, vbscript has a function called MonthName that does what this
function is doing.
Probably only in English, Bob.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 2 '06 #3
Evertjan. wrote:
Bob Barrows [MVP] wrote on 02 sep 2006 in
microsoft.public.inetserver.asp.general:
>>Function getMonthName(iMonth)

FYI, vbscript has a function called MonthName that does what this
function is doing.

Probably only in English, Bob.
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"
Sep 2 '06 #4
Evertjan. wrote:
>FYI, vbscript has a function called MonthName that
does what this function is doing.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
Probably only in English, Bob.
With the exception of the [case else] clause, MonthName() does exactly the
same thing as his function. In English or any other language.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Sep 2 '06 #5
Dave Anderson wrote on 02 sep 2006 in
microsoft.public.inetserver.asp.general:
Evertjan. wrote:
>>FYI, vbscript has a function called MonthName that
does what this function is doing.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>
Probably only in English, Bob.

With the exception of the [case else] clause, MonthName() does exactly
the same thing as his function. In English or any other language.
Probably, but we foreign language programmers need a more versatile
function than the standard one.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 2 '06 #6
Thank You
Kevin

"Kevin Raleigh" <kr******@sbcglobal.netwrote in message
news:fr******************************@giganews.com ...
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>&nbsp;</td>"
end if
next

'close the row
response.write "</tr>"
next

%>

</table>

<br><br>
hello again
</body>
</html>


Sep 2 '06 #7
Kevin Raleigh wrote on 03 sep 2006 in
microsoft.public.inetserver.asp.general:
> 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
Using a bit of Jscript in ASP just makes life easier, for me at least:

<script runat='server' language='jscript'>
function getMonthName(m){
var temp = 'January/February/March/April/May/'+
'June/July/August/September/October/November/December';

return temp.split('/')[m-1]+'';
};
</script>

The function is perfectly usable in VBscript <% ... %>
and will return the string "undefined" when the argument is
any other number.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 3 '06 #8
Evertjan. wrote on 03 Sep 2006 07:19:40 GMT:
Kevin Raleigh wrote on 03 sep 2006 in
microsoft.public.inetserver.asp.general:
>> 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
Using a bit of Jscript in ASP just makes life easier, for me at least:

<script runat='server' language='jscript'>
function getMonthName(m){
var temp = 'January/February/March/April/May/'+
'June/July/August/September/October/November/December';

return temp.split('/')[m-1]+'';
};
</script>

The function is perfectly usable in VBscript <% ... %>
and will return the string "undefined" when the argument is
any other number.

You can do pretty much the same thing in VBScript using Split on a string,
or using Array directly to create the array in a single line, eg:

Function getMonthName(m)
temp = Array("January","February",...)
getMonthName = temp(m-1)
End Function

Of course, if m is not a number between 1 and 12 then it'll throw an error,
but there should be some validation added to the function anyway.

Dan
Sep 4 '06 #9
Evertjan. wrote:
>With the exception of the [case else] clause, MonthName()
does exactly the same thing as his function. In English or
any other language.

Probably, but we foreign language programmers need a more
versatile function than the standard one.
That really has nothing to do with this thread. Nothing is stopping you from
writing one, however:

Date.prototype.MonthName = function() {
return [
"januari","februari","maart","april",
"mei","juni","juli","augustus",
"september","oktober","november","december"
][this.getMonth()]
}

var D = new Date()
Response.Write(D.MonthName())


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Sep 4 '06 #10
Daniel Crichton wrote on 04 sep 2006 in
microsoft.public.inetserver.asp.general:
Evertjan. wrote on 03 Sep 2006 07:19:40 GMT:
>Using a bit of Jscript in ASP just makes life easier, for me at
least:

<script runat='server' language='jscript'>
function getMonthName(m){
var temp = 'January/February/March/April/May/'+
'June/July/August/September/October/November/December';

return temp.split('/')[m-1]+'';
};
</script>

The function is perfectly usable in VBscript <% ... %>
and will return the string "undefined" when the argument is
any other number.


You can do pretty much the same thing in VBScript using Split on a
string, or using Array directly to create the array in a single line,
eg:

Function getMonthName(m)
temp = Array("January","February",...)
getMonthName = temp(m-1)
End Function

Of course, if m is not a number between 1 and 12 then it'll throw an
error, but there should be some validation added to the function
anyway.
Not anyway, as in my jscript function the validation is included
returning a string(!) containing "undefined".
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 4 '06 #11
Evertjan. wrote on 04 Sep 2006 13:24:57 GMT:
Daniel Crichton wrote on 04 sep 2006 in
microsoft.public.inetserver.asp.general:
>Evertjan. wrote on 03 Sep 2006 07:19:40 GMT:
>>Using a bit of Jscript in ASP just makes life easier, for me at
least:

<script runat='server' language='jscript'>
function getMonthName(m){
var temp = 'January/February/March/April/May/'+
'June/July/August/September/October/November/December';

return temp.split('/')[m-1]+'';
};
</script>

The function is perfectly usable in VBscript <% ... %>
and will return the string "undefined" when the argument is
any other number.
You can do pretty much the same thing in VBScript using Split on a
string, or using Array directly to create the array in a single line,
eg:

Function getMonthName(m)
temp = Array("January","February",...)
getMonthName = temp(m-1)
End Function

Of course, if m is not a number between 1 and 12 then it'll throw an
error, but there should be some validation added to the function
anyway.

Not anyway, as in my jscript function the validation is included
returning a string(!) containing "undefined".

The note about validation applied to my VBScript solution, I'm well aware
that JScript has a different mechanism for dealing with things like this ;)

Dan
Sep 4 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

50
by: jacob navia | last post by:
As everybody knows, the C language lacks a way of specifying bounds checked arrays. This situation is intolerable for people that know that errors are easy to do, and putting today's powerful...
22
by: jacob navia | last post by:
A function like strcpy takes now, two unbounded pointers. Unbounded pointers, i.e. pointers where there is no range information, have catastrophic failure modes specially when *writing* to main...
6
by: Flip | last post by:
I'm reading the O'Reilly's Progamming C# book and I have a question about array bounds checking. On page 174, near the top, they show an example where c# does indeed to array bounds checking cause...
1
by: noleander | last post by:
Hey. I'm new to Visual C++. I've got a large application, and I need to make sure all array accesses are within bounds. Back on Unix we had a tool called Purify that detected array-out-of-bounds...
0
by: scotthutchinson | last post by:
I have a .NET Remoting object hosted in IIS6 on Windows Server 2003 (happens before and after installing SP1) at an endpoint (ASP.NET application virtual folder) named "CompanyXYZReporting". The...
8
by: ais523 | last post by:
I've checked the FAQ for this and couldn't find the answer. Is the following code snippet portable? int a; a=6; printf("%d\n",(*a)); This prints "6" on my compiler. I've been told it's...
11
by: Frederick Gotham | last post by:
In another thread recently, there was discussed the accessing of array indices which were out of bounds. Obviously, the following code is bogus: int arr; arr = 4; Take the following snippet...
7
by: Frederick Gotham | last post by:
Over on comp.lang.c, we've been discussing the accessing of array elements via subscript indices which may appear to be out of range. In particular, accesses similar to the following: int arr; ...
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
7
by: polas | last post by:
Afternoon everyone. I have a quick question about standard C. Generally speaking, in my experience, whenever one accesses an array there is never any bounds checking done (either statically...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.