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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declaring a function to destroy varibles at End Sub

Status
Not open for further replies.

joelwenzel

Programmer
Jun 28, 2002
448
Is there a way to create variables in a function so that they are destroyed when the function is finished processing?

I want to be able to declare a variable in two separate functions that have the same name but I cannot if I can't destroy it at the end of the function
 
Read up on variable scope. Specifically, refer to the documentation on the Dim statement.

Variables defined at the procedure level are ONLY available while that procedure is executing. The variables are released once the fall out of scope. IE,

MsgBox Yo()
MsgBox Bro()

Private Function Yo()
Dim lvar
lvar="Yo"
Yo=lvar
End Function
Private Function Bro()
Bro = lvar
End Function Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top