[AccessD] Using Multidimensional Arrays

Shamil Salakhetdinov shamil at users.mns.ru
Tue Mar 7 08:51:54 CST 2006


Penn,

yes, why not use user defined types/structures?

Public Type myType
    FirstName As String
    LastName As String
    EmailAddress As String
End Type

Public Function a_Test()
Dim avar(0 To 99) As myType
Dim i As Integer
    For i = 0 To 99
       With avar(i)
         .FirstName = "FN" & i
         .LastName = "LN" & i
         .EmailAddress = "EA" & i & "@gmail.com"
       End With
    Next i
End Function

Custom classes could be an overkill here but if you will have several public 
methods (like First and Last name concatenation) then custom class os 
looking as the best candidate:

' class module myClass
Public FirstName As String
Public LastName As String
Public EmailAddress As String

Public Property Get FullName() As String
    FullName = FirstName & " " & LastName
End Property

' test
Public Function a_test1()
Dim avar(0 To 99) As myClass
Dim i As Integer
    For i = 0 To 99
       Set avar(i) = New myClass
       With avar(i)
         .FirstName = "FN" & i
         .LastName = "LN" & i
         .EmailAddress = "EA" & i & "@gmail.com"
       End With
    Next i
End Function

Classes can be also/should be better(?) used with collections - then 
additionally you cah have mnemonic access to collection memebers by symbolic 
key like fullname assuming it's unique (or you can define a surrogate key 
unique value property):

Public Function a_test2()
Dim avar  As myClass
Dim col As New Collection
Dim i As Integer
    For i = 0 To 99
       Set avar = New myClass
       With avar
         .FirstName = "FN" & i
         .LastName = "LN" & i
         .EmailAddress = "EA" & i & "@gmail.com"
          col.Add avar, .FullName
       End With
    Next i
End Function


Shamil

----- Original Message ----- 
From: "Penn White" <ecritt1 at alltel.net>
To: "Access Developers discussion and problem solving" 
<accessd at databaseadvisors.com>
Sent: Tuesday, March 07, 2006 1:29 PM
Subject: [AccessD] Using Multidimensional Arrays


> ACC03 - I'm sending out emails from Access to a list of recipients 
> selected
> from a listbox.  Since I don't have Exchange Server, I can't be sure that
> the entries in the 'workstations' Outlook Contact list is up-to-date.
> Consequently, I have to verity first that the Contact is in that
> workstation's Outlook Contact list and second that the email address 
> hasn't
> changed.  It's a bit messy and may be time consuming since every single
> email will have to check all the recipients before being sent but there
> would rarely be more than 10 recipients for an email and more usually only
> 2-3 and I can't think of any other way to do it.
>
> I was thinking of creating a multi-dimensional array to hold the 
> FirstName,
> LastName and Email address for each selected recipient but I can't figure
> out how to do it.  The number of entries in the array will vary depending 
> on
> how many recipients are selected.  There may not necessarily be a first 
> name
> and the 'last name' may actually be a string of several words, like 
> "Belton
> Manufacturing" for example.
>
> Once the array is created, I'll need to concatenate the first and last 
> names
> and check them against the existing entries in Outlook Contacts, updating 
> or
> adding as necessary.  If I can get the entries out of the array, that 
> won't
> be hard, I've already done if before and have developed functions for the
> various pieces.
>
> I've also seen some comparisons between using structures and arrays and
> maybe I should be using a structure here.
>
> I'm a bit befuddled.
>
> Penn
>
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com 




More information about the AccessD mailing list