Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Newbie question, How do I know if an array is 'valid'

50 views
Skip to first unread message

Fredrik Melin

unread,
Nov 10, 2000, 3:00:00 AM11/10/00
to
Hi.

If I declare an array like this

Dim sKeyArray() as String

how can I know if the array is set or not, eg

MsgBox sKeyArray(0) returns Subscript out of range

but if I later in the program
sKeyArray = frmMain.fnReturn_Array
Then the array is set and everyting works.

But before its set how can I check if its empty or not?

Regards
Fredrik

Laura N Meyerovich

unread,
Nov 11, 2000, 3:00:00 AM11/11/00
to
Did you try to use UBound and LBound functions?

Fredrik Melin wrote:

--
Laura Meyerovich
Magnet Systems
phone (401) 742-1636
fax (520) 438-5537
lmeye...@home.com

Visual Basic, MS Access, Crystal Reports, SQL Server, and ASP
independent consultant.
Development, system integration, database design and data conversions.

Adrian Wilkins

unread,
Nov 15, 2000, 3:00:00 AM11/15/00
to

"Laura N Meyerovich" <lmeye...@home.com> wrote in message
news:3A0DD576...@home.com...

> Did you try to use UBound and LBound functions?

This also generates the same error for an undimensioned dynamic array.

Having wrestled with this, I have concluded that it is best to just redim
the array to (0) immediately after declaring it.


Simon Smith

unread,
Nov 16, 2000, 3:00:00 AM11/16/00
to
On Wed, 15 Nov 2000 15:21:01 -0000 in article
<8uua1r$a9n$1...@soap.pipex.net>, "Adrian Wilkins"
<Adr...@spamdefeater.ascribe.com> wrote:

Public Function IsDimmed(anArray As Variant) As Boolean

Dim i As Long

On Error GoTo IDErr
i = LBound(anArray)
IsDimmed = True
Exit Function

IDErr:
IsDimmed = False
Exit Function

End Function

e.g.

Private Sub Command1_Click()

Dim Arr() As Integer

MsgBox IsDimmed(Arr)
ReDim Arr(0)
MsgBox IsDimmed(Arr)

End Sub


Not elegant but it works.


Simon Smith
www.quintuslink.com
Simon at Quintuslink dot com

0 new messages