IsArray doesn"t work with array var populated with xxx.GetRows()

IsArray doesn"t work with array var populated with xxx.GetRows()

am 20.11.2004 22:14:22 von Laphan

Hi All

I'm using .getRows() with a local var array instead of doing a recursive
loop so that I'm being a good ASP newvbie and closing my object i/o's (the
recordset in this case) as quick as possible.

My problem is that I can't seem to use this to complete good effect because
the IsArray statement doesn't seem to work with a local var array that has
or has not been populated with the .getRows() property.

To explain, I used to do the following recursive loop (simplified to show a
concise example):

.... create/open objects

IF NOT oRSv.EOF THEN
Do while not oRSv.EOF and not ii > cMax
Response.Write "" & oRSv("Product") & ""
oRSv.MoveNext
ii = ii + 1
Loop
END IF

.... close objects

I was told that the above is a bit of a resource hogger because I am
constantly calling the object and leaving it open whilst I do the loop, so I
moved on to using the .GetRows() method. This does seem quicker, but the
following has a problem if the recordset basically doesn't bring anything
back:

IF NOT oRSv.EOF THEN arrSQLData = oRSv.GetRows
oRSv.close

IF IsArray(arrSQLData) THEN << SEE *** BELOW
call ShowAboutUsContent()
ELSE
call NoAboutUsContent()
END IF

*** = if there is nothing in the oRSv.GetRows the IsArray() test still goes
through as true and then fouls up the 'ShowAboutUsContent()' sub because
there is nothing to display. I want to use this quick and easy test because
it is clean and easy to read, ie if there is some content then do
ShowAbout... sub if not then do NoAboutUs..., but this test doesn't seem to
work. To get round this for now I have had to do the following:

IF NOT oRSv.EOF THEN
arrSQLData = oRSv.GetRows
call ShowAboutUsContent()
ELSE
call NoAboutUsContent()
END IF
oRSv.close

Although the above works I'm not being efficient because one of the above
subs has to go through to completion before I can close the oRSv.close (in
this case).

Can somebody explain what I am doing wrong with the IsArray. Am I using it
in the way that it is intended?

Thanks

Laphan

Re: IsArray doesn"t work with array var populated with xxx.GetRows()

am 21.11.2004 00:31:00 von David Morgan

Hi

Looks fine to me really.

I do this...

Set objRs = objConn.Execute(stSql, , adCmdText)
If Not objRs.EOF Then
bHasResults = True
arrResults = objRs.GetRows
iResults = UBound(arrResults, 2)
End If
objRs.Close
Set objRs = Nothing

If bHasResults Then
For i = 0 To iResults
Response.Write arrResults(0, i)
Next
End If

(Use a record count variable like iResults to save repeatedly doing a UBound
on an array, the size of which, will not change.)


"Laphan" wrote in message
news:OPc7wZ0zEHA.1400@TK2MSFTNGP11.phx.gbl...
> Hi All
>
> I'm using .getRows() with a local var array instead of doing a recursive
> loop so that I'm being a good ASP newvbie and closing my object i/o's (the
> recordset in this case) as quick as possible.
>
> My problem is that I can't seem to use this to complete good effect
because
> the IsArray statement doesn't seem to work with a local var array that has
> or has not been populated with the .getRows() property.
>
> To explain, I used to do the following recursive loop (simplified to show
a
> concise example):
>
> ... create/open objects
>
> IF NOT oRSv.EOF THEN
> Do while not oRSv.EOF and not ii > cMax
> Response.Write "" & oRSv("Product") & ""
> oRSv.MoveNext
> ii = ii + 1
> Loop
> END IF
>
> ... close objects
>
> I was told that the above is a bit of a resource hogger because I am
> constantly calling the object and leaving it open whilst I do the loop, so
I
> moved on to using the .GetRows() method. This does seem quicker, but the
> following has a problem if the recordset basically doesn't bring anything
> back:
>
> IF NOT oRSv.EOF THEN arrSQLData = oRSv.GetRows
> oRSv.close
>
> IF IsArray(arrSQLData) THEN << SEE *** BELOW
> call ShowAboutUsContent()
> ELSE
> call NoAboutUsContent()
> END IF
>
> *** = if there is nothing in the oRSv.GetRows the IsArray() test still
goes
> through as true and then fouls up the 'ShowAboutUsContent()' sub because
> there is nothing to display. I want to use this quick and easy test
because
> it is clean and easy to read, ie if there is some content then do
> ShowAbout... sub if not then do NoAboutUs..., but this test doesn't seem
to
> work. To get round this for now I have had to do the following:
>
> IF NOT oRSv.EOF THEN
> arrSQLData = oRSv.GetRows
> call ShowAboutUsContent()
> ELSE
> call NoAboutUsContent()
> END IF
> oRSv.close
>
> Although the above works I'm not being efficient because one of the above
> subs has to go through to completion before I can close the oRSv.close (in
> this case).
>
> Can somebody explain what I am doing wrong with the IsArray. Am I using
it
> in the way that it is intended?
>
> Thanks
>
> Laphan
>
>

Re: IsArray doesn"t work with array var populated with xxx.GetRows()

am 21.11.2004 12:52:29 von Laphan

A simple flag to test for data - Dave you're a genius!!!

Many thanks.

Rgds

Laphan


David Morgan wrote in message
news:elVwZk1zEHA.804@TK2MSFTNGP12.phx.gbl...
Hi

Looks fine to me really.

I do this...

Set objRs = objConn.Execute(stSql, , adCmdText)
If Not objRs.EOF Then
bHasResults = True
arrResults = objRs.GetRows
iResults = UBound(arrResults, 2)
End If
objRs.Close
Set objRs = Nothing

If bHasResults Then
For i = 0 To iResults
Response.Write arrResults(0, i)
Next
End If

(Use a record count variable like iResults to save repeatedly doing a UBound
on an array, the size of which, will not change.)


"Laphan" wrote in message
news:OPc7wZ0zEHA.1400@TK2MSFTNGP11.phx.gbl...
> Hi All
>
> I'm using .getRows() with a local var array instead of doing a recursive
> loop so that I'm being a good ASP newvbie and closing my object i/o's (the
> recordset in this case) as quick as possible.
>
> My problem is that I can't seem to use this to complete good effect
because
> the IsArray statement doesn't seem to work with a local var array that has
> or has not been populated with the .getRows() property.
>
> To explain, I used to do the following recursive loop (simplified to show
a
> concise example):
>
> ... create/open objects
>
> IF NOT oRSv.EOF THEN
> Do while not oRSv.EOF and not ii > cMax
> Response.Write "" & oRSv("Product") & ""
> oRSv.MoveNext
> ii = ii + 1
> Loop
> END IF
>
> ... close objects
>
> I was told that the above is a bit of a resource hogger because I am
> constantly calling the object and leaving it open whilst I do the loop, so
I
> moved on to using the .GetRows() method. This does seem quicker, but the
> following has a problem if the recordset basically doesn't bring anything
> back:
>
> IF NOT oRSv.EOF THEN arrSQLData = oRSv.GetRows
> oRSv.close
>
> IF IsArray(arrSQLData) THEN << SEE *** BELOW
> call ShowAboutUsContent()
> ELSE
> call NoAboutUsContent()
> END IF
>
> *** = if there is nothing in the oRSv.GetRows the IsArray() test still
goes
> through as true and then fouls up the 'ShowAboutUsContent()' sub because
> there is nothing to display. I want to use this quick and easy test
because
> it is clean and easy to read, ie if there is some content then do
> ShowAbout... sub if not then do NoAboutUs..., but this test doesn't seem
to
> work. To get round this for now I have had to do the following:
>
> IF NOT oRSv.EOF THEN
> arrSQLData = oRSv.GetRows
> call ShowAboutUsContent()
> ELSE
> call NoAboutUsContent()
> END IF
> oRSv.close
>
> Although the above works I'm not being efficient because one of the above
> subs has to go through to completion before I can close the oRSv.close (in
> this case).
>
> Can somebody explain what I am doing wrong with the IsArray. Am I using
it
> in the way that it is intended?
>
> Thanks
>
> Laphan
>
>

Re: IsArray doesn"t work with array var populated with xxx.GetRows()

am 21.11.2004 15:21:07 von reb01501

Laphan wrote:
>
> IF NOT oRSv.EOF THEN arrSQLData = oRSv.GetRows
> oRSv.close
>
> IF IsArray(arrSQLData) THEN << SEE *** BELOW
> call ShowAboutUsContent()
> ELSE
> call NoAboutUsContent()
> END IF
>

Show us the dim statement for the arrSQLData. It should be

dim arrSQLData

not

dim arrSQLData()


If you use the second version, it will still be an array when you test it
with IsArray().

Bob Barrows

--
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"