473,387 Members | 1,464 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,387 software developers and data experts.

Checking status of an array

Good day folks.

Within an ASP I'm working on I need to check whether an array is empty or
not.

Code:
Dim somearray()
'other code: array might have been populated, maybe not
if somearray() <> "" Then 'this is the line that hangs debugging using VID
'code if array is populated
else
'code if array is empty
end if

My problem is coming up when I debug(Using VID) I get this error:
An exception of type 'Microsoft VBScript runtime error: Subscript out of
range' was not handled.

But when I actually launch the page I don't get any errors. Of course if I
put in On Error Resume Next, and I run in debug mode I don't get any errors
through VID and I still obviously I don't get any errors launching the page.

Thanks for any insight from this ASP Newbie
Jul 19 '05 #1
3 15795
David,

You need to make sure you are not going beyond the array bounds, the error
you are getting is because you are not doing so.

Use the UBound() function that returns the last index within the array's
dimension. So, if the array contains 20 elements, the UBound function will
return 19.

lastIndex = UBound(someArray, 1)

Look up the VB help for more info on the method.
--
Manohar Kamath
Editor, .netBooks
www.dotnetbooks.com
"David P. Jessup" <davidATimntDASHtechDOTcom> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
Good day folks.

Within an ASP I'm working on I need to check whether an array is empty or
not.

Code:
Dim somearray()
'other code: array might have been populated, maybe not
if somearray() <> "" Then 'this is the line that hangs debugging using VID 'code if array is populated
else
'code if array is empty
end if

My problem is coming up when I debug(Using VID) I get this error:
An exception of type 'Microsoft VBScript runtime error: Subscript out of
range' was not handled.

But when I actually launch the page I don't get any errors. Of course if I put in On Error Resume Next, and I run in debug mode I don't get any errors through VID and I still obviously I don't get any errors launching the page.
Thanks for any insight from this ASP Newbie

Jul 19 '05 #2
VBScript's handling of array bounds checking leaves some to be desired. I
get inconsistent results with IsArray(somearray) depending on the state of
the array - GetRows on an empty recordset is a big culprit. What I've done
is write a function (I call it IsArrayEx, and it handles two dimensional
arrays which are what I work with most of the time) that works this way:

Function IsArrayEx(inArray, intUpperBound)
'--- this doesn't address whether or not there's data, only if the array
can be used
IsArrayEx = false

on error resume next

dim tmpVar
tmpVar = inArray(0, ubound(inArray, intUpperBound))
if err.number = 0 then
'--- the array is useable...
IsArrayEx = true
end if
End Function

"David P. Jessup" <davidATimntDASHtechDOTcom> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
Good day folks.

Within an ASP I'm working on I need to check whether an array is empty or
not.

Code:
Dim somearray()
'other code: array might have been populated, maybe not
if somearray() <> "" Then 'this is the line that hangs debugging using VID 'code if array is populated
else
'code if array is empty
end if

My problem is coming up when I debug(Using VID) I get this error:
An exception of type 'Microsoft VBScript runtime error: Subscript out of
range' was not handled.

But when I actually launch the page I don't get any errors. Of course if I put in On Error Resume Next, and I run in debug mode I don't get any errors through VID and I still obviously I don't get any errors launching the page.
Thanks for any insight from this ASP Newbie

Jul 19 '05 #3
WIlliam Morris wrote:
VBScript's handling of array bounds checking leaves some to be
desired. I get inconsistent results with IsArray(somearray)
depending on the state of the array - GetRows on an empty recordset
is a big culprit.


This has never failed me:

'open the recordset, then:
dim ar
if not rs.eof then ar = rs.GetRows
rs.close: set rs=nothing
if isarray(ar) then
'process data
else
'handle no-records event
end if

--
HTH,
Bob Barrows - ASP MVP
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #4

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

Similar topics

3
by: FLEB | last post by:
I have a function which should convey two things upon its completion. First, the return value of the function, consisting of some text. Second, it should convey an "error status", which, could be...
2
by: Marc S. Gibian | last post by:
I am putting together a Perl tool to manage a large set of tasks related to building a rather complex set of software. One of the goals for moving to Perl is to provide very rigorous error checking...
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...
2
by: Maziar Aflatoun | last post by:
Hi everyone, I am reading and displaying data rows from my database where the first column contains the Status checkbox. I like to enable my users to change the status of individual rows by...
21
by: jacob navia | last post by:
Many compilers check printf for errors, lcc-win32 too. But there are other functions that would be worth to check, specially memset. Memset is used mainly to clear a memory zone, receiving a...
7
by: Hulo | last post by:
In a C program I am required to enter three numbers (integers) e.g. 256 7 5 on execution of the program. C:\> 256 7 5 There should be spaces between the three numbers and on pressing "enter",...
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...
1
by: runway27 | last post by:
hi I am using MySQL - 4.1.22 when i use the following sql query $result = mysql_query("SHOW tablename STATUS FROM databasename;"); i have also tried = $result = mysql_query("SHOW tablename...
2
by: Sudhakar | last post by:
hi I am using MySQL - 4.1.22 when i use the following sql query $result = mysql_query("SHOW tablename STATUS FROM databasename;"); i have also tried = $result = mysql_query("SHOW tablename...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.