×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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?

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

Here is some sample code for tweaking arrays:

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.

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

(OP)
what if i have 35 different arrays?
should i do redimension each n every before unloading?

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

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.

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

(OP)
thanks all of you for ur replieZ .... ive sorted out the problem :)

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

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

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

(OP)
well most of them are private, while very few are Global too.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources