
- VBA Tutorial
- VBA - Home
- VBA - Overview
- VBA - Excel Macros
- VBA - Excel Terms
- VBA - Macro Comments
- VBA - Message Box
- VBA - Input Box
- VBA - Variables
- VBA - Constants
- VBA - Operators
- VBA - Decisions
- VBA - Loops
- VBA - Strings
- VBA - Date and Time
- VBA - Arrays
- VBA - Functions
- VBA - Sub Procedure
- VBA - Events
- VBA - Error Handling
- VBA - Excel Objects
- VBA - Text Files
- VBA - Programming Charts
- VBA - Userforms
- VBA Useful Resources
- VBA - Quick Guide
- VBA - Useful Resources
- VBA - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
VBA - Erase Function
The Erase Function is used to reset the values of fixed size arrays and free the memory of the dynamic arrays. It behaves depending upon the type of the arrays.
Syntax
Erase ArrayName
- Fixed numeric array, each element in an array is reset to Zero.
- Fixed string array, each element in an array is reset to Zero length " ".
- Array of objects, each element in an array is reset to special value Nothing.
Example
Add a button and add the following function.
Private Sub Constant_demo_Click() Dim NumArray(3) NumArray(0) = "VBScript" NumArray(1) = 1.05 NumArray(2) = 25 NumArray(3) = #23/04/2013# Dim DynamicArray() ReDim DynamicArray(9) ' Allocate storage space. Erase NumArray ' Each element is reinitialized. Erase DynamicArray ' Free memory used by array. ' All values would be erased. msgbox("The value at Zeroth index of NumArray is " & NumArray(0)) msgbox("The value at First index of NumArray is " & NumArray(1)) msgbox("The value at Second index of NumArray is " & NumArray(2)) msgbox("The value at Third index of NumArray is " & NumArray(3)) End Sub
When you execute the above function, it produces the following output.
The value at Zeroth index of NumArray is The value at First index of NumArray is The value at Second index of NumArray is The value at Third index of NumArray is
vba_arrays.htm
Advertisements