By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Clearing an array.

P: 59
Sorry for the stupid question... how do I clear an array ?

I'm using an OE email sending code that I found on this forum.
when I send to a second persone it tries also to send to the first one (everytime it just add a new email address to the array)

Expand|Select|Wrap|Line Numbers
  1.  Private Sub RecipientAdd(ByVal lngType As Long, Optional ByVal strName As String, Optional ByVal strAddress As String)
  2. Dim r As MAPIRecip
  3. r.RecipClass = lngType
  4. If strName <> "" Then r.Name = StrConv(strName, vbFromUnicode)
  5. If strAddress <> "" Then r.Address = StrConv(strAddress, vbFromUnicode)
  6. ReDim Preserve mAr(lAr)
  7. mAr(lAr) = r
  8. lAr = lAr + 1
  9. End Sub 
now I'm trying to clear the array each time:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub RecipientTo(ByVal lngType As Long, Optional ByVal strName As String, Optional ByVal strAddress As String)
  2. Dim r As MAPIRecip
  3. r.RecipClass = lngType
  4. If strName <> "" Then r.Name = StrConv(strName, vbFromUnicode)
  5. If strAddress <> "" Then r.Address = StrConv(strAddress, vbFromUnicode)
  6. lAr = 0
  7. ReDim mAr(lAr)
  8. mAr(lAr) = r
  9. End Sub 
I still want to use an array, because I want to use both option. sometimes adding more address, and sometimes only sending to one new email address.

why my code doesn't work well ?

thanks in advance, Idan
Jan 26 '08 #1
Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,186
Assuming there are no failures in the code, the only thing I can think of is that we don't see the definitions of either lAr or mAr. Do you use :
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
If not then you certainly should.
lAr seems to me to be LAR, but perhaps it is written sometimes as IAR. In some fonts they're very hard to differentiate.
Just some thoughts. I would use the ReDim statement without the Preserve keyword myself if I wanted to do what you're trying to do.
Jan 26 '08 #2

ADezii
Expert 5K+
P: 8,597
Sorry for the stupid question... how do I clear an array ?

I'm using an OE email sending code that I found on this forum.
when I send to a second persone it tries also to send to the first one (everytime it just add a new email address to the array)

Expand|Select|Wrap|Line Numbers
  1.  Private Sub RecipientAdd(ByVal lngType As Long, Optional ByVal strName As String, Optional ByVal strAddress As String)
  2. Dim r As MAPIRecip
  3. r.RecipClass = lngType
  4. If strName <> "" Then r.Name = StrConv(strName, vbFromUnicode)
  5. If strAddress <> "" Then r.Address = StrConv(strAddress, vbFromUnicode)
  6. ReDim Preserve mAr(lAr)
  7. mAr(lAr) = r
  8. lAr = lAr + 1
  9. End Sub 
now I'm trying to clear the array each time:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub RecipientTo(ByVal lngType As Long, Optional ByVal strName As String, Optional ByVal strAddress As String)
  2. Dim r As MAPIRecip
  3. r.RecipClass = lngType
  4. If strName <> "" Then r.Name = StrConv(strName, vbFromUnicode)
  5. If strAddress <> "" Then r.Address = StrConv(strAddress, vbFromUnicode)
  6. lAr = 0
  7. ReDim mAr(lAr)
  8. mAr(lAr) = r
  9. End Sub 
I still want to use an array, because I want to use both option. sometimes adding more address, and sometimes only sending to one new email address.

why my code doesn't work well ?

thanks in advance, Idan
I think you are referring to the Erase Statement:
  1. Erase reinitializes the elements of fixed-size arrays and releases dynamic-array storage space.
  2. Syntax
    Expand|Select|Wrap|Line Numbers
    1. Erase arraylist
  3. The required arraylist argument is one or more comma-delimited array variables to be erased.
  4. Erase behaves differently depending on whether an array is fixed-size (ordinary) or dynamic. Erase recovers no memory for fixed-size arrays. Erase sets the elements of a fixed array as follows:
  5. Type of Array Effect of Erase on Fixed-Array Elements
    1. Fixed numeric array Sets each element to zero.
    2. Fixed string array (variable length) Sets each element to a zero-length string ("").
    3. Fixed string array (fixed length) Sets each element to zero.
    4. Fixed Variant array Sets each element to Empty.
    5. Array of user-defined types Sets each element as if it were a separate variable.
    6. Array of objects Sets each element to the special value Nothing.
  6. Erase frees the memory used by dynamic arrays. Before your program can refer to the dynamic array again, it must redeclare the array variable's dimensions using a ReDim statement.
  7. This example uses the Erase statement to reinitialize the elements of fixed-size arrays and deallocate dynamic-array storage space.
    Expand|Select|Wrap|Line Numbers
    1. ' Declare array variables.
    2. Dim NumArray(10) As Integer           ' Integer array.
    3. Dim StrVarArray(10) As String         ' Variable-string array.
    4. Dim StrFixArray(10) As String * 10    ' Fixed-string array.
    5. Dim VarArray(10) As Variant           ' Variant array.
    6. Dim DynamicArray() As Integer         ' Dynamic array.
    7. ReDim DynamicArray(10)                ' Allocate storage space.
    8.  
    9. Erase NumArray                        ' Each element set to 0.
    10. Erase StrVarArray                     ' Each element set to zero-length string ("").    
    11. Erase StrFixArray                     ' Each element set to 0.
    12. Erase VarArray                        ' Each element set to Empty.
    13. Erase DynamicArray                    ' Free memory used by array.
Jan 27 '08 #3

P: 59
thanks for the information, that was exactly what I wanted to know...
there was another problam that wouldn't let it work.. but I found it as well..
Jan 27 '08 #4

NeoPa
Expert Mod 15k+
P: 31,186
Nice one again ADezii. I'd forgotten all about the Erase statement.
Jan 27 '08 #5

ADezii
Expert 5K+
P: 8,597
Nice one again ADezii. I'd forgotten all about the Erase statement.
Thanks, NeoPa. This was an easy one, just knowing what to use, then Copy and Paste from the Help Files. They 'all' should be so easy. (LOL).
Jan 27 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.