473,698 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15824
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(someArra y, 1)

Look up the VB help for more info on the method.
--
Manohar Kamath
Editor, .netBooks
www.dotnetbooks.com
"David P. Jessup" <davidATimntDAS HtechDOTcom> wrote in message
news:On******** ******@tk2msftn gp13.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(somearr ay) 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(inArr ay, 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" <davidATimntDAS HtechDOTcom> wrote in message
news:On******** ******@tk2msftn gp13.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(somearr ay)
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
1724
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 either a simple "success", or a number of levels of failure. (For the record, it's a logon script indicating success/failure, but I'll probably use this elsewhere.) The way I see it, I have a couple options, maybe more:
2
4460
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 and handling. One area that has me puzzled is error checking some of the file system operations. Just simple things such as open, rename, unlink, print and some others ... all the sample code I've seen uses them in a form of: open(...) || die...
6
3667
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 the example shows a System.IndexOutOfRangeException being thrown. However, in the very next section (Jagged arrays) they have warning section that says "Java programmers take note: While Java does bounds checking on array use, C# does not." ...
2
6631
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 checking and unchecking the checkbox column. I like to update the status in the database for the column where the status was changed. This is what I'm doing so far
21
8765
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 pointer to the start, the value (most of the time zero) and the size of the memory array to clear. Problems appear when the size given is not the size of the object given as its first argument. For instance void fn(void)
7
2633
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", further processing is done. The problem requires me to check whether three numbers have actually been entered in the input line and to warn if less or more numbers have been entered.
125
6558
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 problem. http://www.jilp.org/vol9/v9paper10.pdf Specifically, they measured the overhead of a bounds
1
2509
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 STATUS FROM databasename"); i get the following error message ====================================================
2
11531
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 STATUS FROM databasename"); i get the following error message
0
8598
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9152
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9014
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7708
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.