Clearing an array.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zivon
    New Member
    • Aug 2007
    • 59

    Clearing an array.

    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)

    Code:
     Private Sub RecipientAdd(ByVal lngType As Long, Optional ByVal strName As String, Optional ByVal strAddress As String)
    Dim r As MAPIRecip
    r.RecipClass = lngType
    If strName <> "" Then r.Name = StrConv(strName, vbFromUnicode)
    If strAddress <> "" Then r.Address = StrConv(strAddress, vbFromUnicode)
    ReDim Preserve mAr(lAr)
    mAr(lAr) = r
    lAr = lAr + 1
    End Sub
    now I'm trying to clear the array each time:

    Code:
     Private Sub RecipientTo(ByVal lngType As Long, Optional ByVal strName As String, Optional ByVal strAddress As String)
    Dim r As MAPIRecip
    r.RecipClass = lngType
    If strName <> "" Then r.Name = StrConv(strName, vbFromUnicode)
    If strAddress <> "" Then r.Address = StrConv(strAddress, vbFromUnicode)
    lAr = 0
    ReDim mAr(lAr)
    mAr(lAr) = r
    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
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32666

    #2
    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 :
    Code:
    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.

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by zivon
      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)

      Code:
       Private Sub RecipientAdd(ByVal lngType As Long, Optional ByVal strName As String, Optional ByVal strAddress As String)
      Dim r As MAPIRecip
      r.RecipClass = lngType
      If strName <> "" Then r.Name = StrConv(strName, vbFromUnicode)
      If strAddress <> "" Then r.Address = StrConv(strAddress, vbFromUnicode)
      ReDim Preserve mAr(lAr)
      mAr(lAr) = r
      lAr = lAr + 1
      End Sub
      now I'm trying to clear the array each time:

      Code:
       Private Sub RecipientTo(ByVal lngType As Long, Optional ByVal strName As String, Optional ByVal strAddress As String)
      Dim r As MAPIRecip
      r.RecipClass = lngType
      If strName <> "" Then r.Name = StrConv(strName, vbFromUnicode)
      If strAddress <> "" Then r.Address = StrConv(strAddress, vbFromUnicode)
      lAr = 0
      ReDim mAr(lAr)
      mAr(lAr) = r
      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
        [CODE=vb]Erase arraylist[/CODE]
      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.
        [CODE=vb]
        ' Declare array variables.
        Dim NumArray(10) As Integer ' Integer array.
        Dim StrVarArray(10) As String ' Variable-string array.
        Dim StrFixArray(10) As String * 10 ' Fixed-string array.
        Dim VarArray(10) As Variant ' Variant array.
        Dim DynamicArray() As Integer ' Dynamic array.
        ReDim DynamicArray(10 ) ' Allocate storage space.

        Erase NumArray ' Each element set to 0.
        Erase StrVarArray ' Each element set to zero-length string ("").
        Erase StrFixArray ' Each element set to 0.
        Erase VarArray ' Each element set to Empty.
        Erase DynamicArray ' Free memory used by array.[/CODE]

      Comment

      • zivon
        New Member
        • Aug 2007
        • 59

        #4
        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..

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32666

          #5
          Nice one again ADezii. I'd forgotten all about the Erase statement.

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by NeoPa
            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).

            Comment

            Working...