How to reset global variables to nothing

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

In a form I store the value of the text box to the global variables in a
module. At some point I need to reset those variables in the module to
nothing. So I tried the following code in the form event, Set
GlobalVariable.Text1 = Nothing or GlobalVariable = vbNullString and both
does not work. Thanks.
 
Unlike some languages, VB/VBA sets the initial value of the variable when
you declare it. Therefore the way to reset it depends on its type.

For numeric types (Integer, Long, Double, Currency, etc), just assign a
zero:
MyGlobal = 0

For String types, assign a zero-length string:
MyGlobal = vbNullString

For Variants, assign the value Empty:
MyGlobal = Empty

For objects (Form, Control, TextBox, Recordset, etc), set to Nothing:
Set MyGlobal = Nothing
 
How about if the variable is the "date" type??

Allen Browne said:
Unlike some languages, VB/VBA sets the initial value of the variable when
you declare it. Therefore the way to reset it depends on its type.

For numeric types (Integer, Long, Double, Currency, etc), just assign a
zero:
MyGlobal = 0

For String types, assign a zero-length string:
MyGlobal = vbNullString

For Variants, assign the value Empty:
MyGlobal = Empty

For objects (Form, Control, TextBox, Recordset, etc), set to Nothing:
Set MyGlobal = Nothing
 
Back
Top