Sad Der
accessd666 at yahoo.com
Thu Jun 2 06:13:55 CDT 2005
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