Best way to empty a variable (1 Viewer)

bodylojohn

Registered User.
Local time
Today, 00:54
Joined
Dec 28, 2005
Messages
205
Hello,

I have searched the web and there are a lot of opinions about this.

I have the following variables:

Code:
curMoney as currency
datDate as date
strString as string
intInteger as integer
What is the best way to empty these variables?

I always use these:

Code:
curMoney = ""
isnull (datDate)
strString = ""
intInteger = 0

Is this the correct way?
 

ted.martin

Registered User.
Local time
Today, 05:54
Joined
Sep 24, 2004
Messages
743
Hello,

I have searched the web and there are a lot of opinions about this.

I have the following variables:

Code:
curMoney as currency
datDate as date
strString as string
intInteger as integer
What is the best way to empty these variables?

I always use these:

Code:
curMoney = ""
isnull (datDate)
strString = ""
intInteger = 0

Is this the correct way?
Yes thats fine but remember, if you Dimension a variable within in a Form's or Report's Sub, then it will empty upon exiting that Sub. If it is a Private Variable in a Form or a Public variable in a module then it may need to be emptied.
 

RoyVidar

Registered User.
Local time
Today, 07:54
Joined
Sep 25, 2000
Messages
805
Why do you wish to empty variables?

There is really no point in doing so, unless you want to stuff something else into them.

The two first, are also meaningless. Assigning "" to a variable of type currency will give run time error 13 - Type Mismatch. The IsNull function is a function to determine whether the passed variable, control, property... is Null or not, it doesn't do anything with the variable. Anyway, a variable of type Date cannot be Null, so...

There is a point in releasing object variables in certain situations. One is often recommended to close everything one has opened, and release all variables that has been instantiated.

There were some bugs with the DAO object model (supposedly fixed), that makes people be a bit "religious" with the closing/releasing of those. Same goes when doing automation.
 

Users who are viewing this thread

Top Bottom