Memory when using VBA

Kenneth

Registered User.
Local time
Today, 21:20
Joined
May 31, 2000
Messages
10
When I initiate the code, and uses the word Dim like for an example:

Dim FieldName as Long
Dim RecordsetName as Recordset

"Some code underneeth, where both objects are beeing used."

"At the end of the code:"

FieldName = Nothing
RecordsetName = Nothing

------
end of code

When I program in C++ I need to stop the objects that I have generated in the code.
This is so that the object doesn't use any of the available memory of the running computer.

Do I have to do the same thing with VBA, and
was it been done, if I set the objects value to Nothing, at the end of the code?

Thanks very much.
 
You can allocate memory in VB, but its easiness as well as functionality doesn't touch C++.

From my personal experience with VB, you can only "allocate"/"delete" datatypes that are not part of the VB language (e.g. Integer, Long, Variant, etc.). You can only do this with datatypes that are either (a) defined in a VB reference (such as rdoQuery) or (b) defined by the user (e.g. you). Your syntax is:
Code:
Dim x as New DataTypeName
' some code goes here
Set x = Nothing
Again, I don't know if this works with all non-VB datatypes, but it does for all of the ones I've worked with.

Frankly, I'd prefer
Code:
int* x;
any day.
smile.gif


- Matt
 
Just read the online-help about DIM (private/public).

Normally all variables are deleted (and no memory is used) when exiting a sub/function.
Just in case you used globals in the header like:

Option explicit
Dim rsMyRecordset as Recordset
Dim dbCurr as Database

Sub ...

then you should set variables definately to nothing to clear memory resources.
 

Users who are viewing this thread

Back
Top Bottom