[AccessD] Check if array is initialized

Joe Rojas JRojas at tnco-inc.com
Thu Jun 2 08:19:01 CDT 2005


What I have done is dim the variable and use the IsArray() function is see
if it's an array. If not then I know I the array is not initialized.

Using your example:

Main
  Dim alngValues
  Call RetrieveSomething(alngValues)
End Main

Public Function RetrieveSomething(byref r_alngMyArray() as Long)
dim lngCntr as long

If Not IsArray(r_alngMyArray) Then
	ReDim r_alngMyArray(0)
End If

for lngCntr = 0 to UBOUND(r_alngMyArray)
  Redim PRESERVE r_alngMyArray(lngCntr)
  r_alngMyArray(lngCntr) = "THIS DOES NOT WORK!"
next lngCntr

End Function



Thanks,
Joe Rojas
IT Manager
TNCO, Inc.
781-447-6661 x7506
jrojas at tnco-inc.com

-----Original Message-----
From: Sad Der [mailto:accessd666 at yahoo.com]
Sent: Thursday, June 02, 2005 7:14 AM
To: Acces User Group
Subject: [AccessD] Check if array is initialized

Hi group,

one of our programmers came to me with a question
regarding an error when the UBOUND() of an array was
retrieved. The error occures when an array has been
DIMmed, without specifing the size, but not REDIMmed.

In the sample below I've created a simple example.
When the function is called a byref array is to be
filled with values. However the line:
  for lngCntr = 0 to UBOUND(r_alngMyArray)
Will always fill since it hasn't been ReDimmed.

I suggested a workaround:
1 - use the function IsInitialized() and check if the
function returns -1. If so the array isnt't
intitialized.

However, is there an official way of handling this
error/problem/occurence?

Thnx

Regards,

SD
--------------------
EXAMPLE
--------------------

Main
  Dim alngValues() as long
  Call RetrieveSomething(alngValues())
End Main

Public Function RetrieveSomething(byref
r_alngMyArray() as Long)
dim lngCntr as long

for lngCntr = 0 to UBOUND(r_alngMyArray)
  Redim PRESERVE r_alngMyArray(lngCntr)
  r_alngMyArray(lngCntr) = "THIS DOES NOT WORK!"
next lngCntr

End Function

------------------
WORKAROUND
------------------
Function IsInitialized(byref r_alngInitialized) as
Long
 On Error Goto error_not_initialized

  IsInitialized = UBOUND(r_alngInitialized)

Exit Function
Goto error_not_initialized
  IsInitialized = -1
End Function


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



This electronic transmission is strictly confidential to TNCO, Inc. and
intended solely for the addressee. It may contain information which is
covered by legal, professional, or other privileges. If you are not the
intended addressee, or someone authorized by the intended addressee to
receive transmissions on behalf of the addressee, you must not retain,
disclose in any form, copy, or take any action in reliance on this
transmission. If you have received this transmission in error, please notify
the sender as soon as possible and destroy this message. While TNCO, Inc.
uses virus protection, the recipient should check this email and any
attachments for the presence of viruses. TNCO, Inc. accepts no liability for
any damage caused by any virus transmitted by this email.



More information about the AccessD mailing list