Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Destructing a variable in VB

Status
Not open for further replies.

RichS

Programmer
Apr 24, 2000
380
US
How do I remove a global variable from memory in visual basic. I want to redim it when I need it and remove it when I no longer need it.

Rich
 
Thanks for the response John. The Erase doesn't work on a long or an integer. Is there a way to erase these types?
 
To my knowledge, you can't destroy or create a global variable in proccess(that is, by clicking on a button or something). However, my question to you is, Why would you want to? Tim

Remember the KISS principle:
Keep It Simple, Stupid!
 
- Tim
It is a variable that will be used infrequently and it is a matter of style that I don't like to leave useless variables hanging around out there with infinite life. I know it's not critical and with the amount of resources used it's immaterial. Just trying to perfect my knowledge of VB.

- John
Thanks for the suggestion. However, I will probably just not worry about the space used.

 
Rich:
Sounds to me like these seldom used variables should not be declared as Public(Global) in the first place. It is good programming practice to AVOID using Public variables.

Try declaring a seldom used variable as a LOCAL variable in a routine, and if you need to, pass that variable to the routine that needs it.

Sometimes you just need that Public variable in place, even though your program might never use it during a run.

As a quick example of where you might need one:

Public booCancel As Boolean

Private Sub cmdCancel_Click()
booCancel = True
End Sub

Private Sub DoWork()
Do While Not booCancel
DoEvents
'do work
Loop
End Sub

Tim

Remember the KISS principle:
Keep It Simple, Stupid!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top