Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Re- Initialising Arrays in multiple forms (or maybe Garbage Collection

Status
Not open for further replies.

Rednyx

Civil/Environmental
Feb 22, 2001
42
0
0
JP
Ive made a programme on multiple forms which are activated from the main Form through buttons.
i am facing a little prob
when user complete the operation from, say form2, he exits from it to the main form, and if he want to perform the same operation he may choose to go back to form 2, but then i face errors as the Arrays that were initialised the first time still have old values in them though last time i have un loaded the form?
how should i prevent this?
 
Replies continue below

Recommended for you

Here is some sample code for tweaking arrays:
Code:
Option Base 1

Dim MyArray() As String

'Initialize array (erases all entries)
Redim MyArray(1)

'Fill with 5 items
For i = 1 to 5
    'Update depth of array - saving existing contents
    Redim Preserve MyArray(i) 
    MyArray(i) = "Entry: " & i
Next i

'Report the contents back
For i = LBound(MyArray) To UBound(MyArray)
    MsgBox MyArray(i)
Next i

'Clear the entire array
Redim MyArray(1)
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
If you want to clear an array, you will have to use the Redim command to do so, unless you want to do it manually. You can do this at the beginning or the end of a procedure that requires them to be cleared. Better yet, you could have a subroutine that clears all of the arrays and just call that routine from each of your forms.

As far as clearing the arrays, it really depends on your needs. Are these arrays global? If they are, you should have a need for them in other routines. If the data is only being used while the form is loaded, you should make the arrays local to the form. Then, they will automatically be released once you close the form.
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
When you are finished using the array, trying erase:

erase myArray 'This frees up the memmory used by the array.


Are the arrays private to the particular form they are on? Or are they global variables?
Troy Williams
fenris@hotmail.com
 
Status
Not open for further replies.
Back
Top