Unsetting/Destroying Variables

  • Thread starter Thread starter Sarah
  • Start date Start date
S

Sarah

I have a variable of certain name - i.e. "MyString" or "MyDate" - how do I
unset any value that may have been assigned to it?
 
You can try setting the variable to Nothing.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
 
Unsetting the value and Destroying the variable are 2 different things. As
the others have said, you could set it = nothing or some other base value if
all you want to do is reset the variable.

Strings are actually reference types and so setting it = nothing won't
really remove it from memory at that moment.
 
Sarah said:
I have a variable of certain name - i.e. "MyString" or "MyDate" - how
do I unset any value that may have been assigned to it?

For refrence types, like strings, assign Nothing (MyString = Nothing). For
value types, there is no "unset". Each value type has a value, that's it.
You can also assign Nothing, but this assigns the _default_ value, i.e. 0
for numeric variables.
 
Hello,

Sarah said:
I have a variable of certain name - i.e. "MyString" or
"MyDate" - how do I unset any value that may have been assigned
to it?

For reference type you can 'clear' the variable by setting it to 'Nothing',
for value types you cannot unset the variable (you can set it to its default
value by setting it to 'Nothing').

\\\
Dim f As Foo = New Foo()
..
..
..
f = Nothing
///

Regards,
Herfried K. Wagner
 
Back
Top