?
Solved

Dynamic array??  Or is that not the best way?

Posted on 2006-05-25
12
Medium Priority
?
266 Views
Last Modified: 2013-12-18
Hi.  Trying to create an agent that will forward emails to specific replica's of another inbox dependant on a time zone.  The email will be forwarded to addresses set up in the keywords view.  However what I need to be able to do is capture multiple addresses in the sendto field and multiple addresses in the CC field.  Each address has to be compared to the keyword view and then a new address is assigned to the email.  The code below will work for just one address in the Sendto field.



      While Not(doc Is Nothing)
            Set docb = view.GetNextDocument(doc)
            Set item = doc.GetFirstItem( "PostedDate" )
            Set dateTime = item.DateTimeValue
            zone = dateTime.TimeZone
            
            Select Case zone
            Case -3, -2, -1, 0, 1, 2, 3, 4, 5
                  Place = "EU"
            Case -11, -10, -9, -8, -7, -6, -5, -4
                  Place = "NA"
            Case  6, 7, 8, 9, 10, 11, 12, -12
                  Place = "AP"
            End Select
            
            Set nam = New NotesName(doc.GetItemValue("SendTo")(0))
            address = nam.Abbreviated
            addresses = s_getKeywordValues(address)
            
            Forall x In addresses
                  contains = Instr(1, x, Place)
                  If contains > 0 Then
                        forwardaddress = s_Right(x, Place)                        
                  End If
            End Forall
            
            Set forwarddoc = New NotesDocument(db)
            Call doc.CopyAllItems( forwarddoc, True )
            forwarddoc.principal = doc.from(0)
            forwarddoc.SendTo = forwardaddress
            Call forwarddoc.Send( False )
            doc.Processed = "Yes"
            Call doc.Save(True, True)
            Set doc = docb
      Wend


The function s_getkeywordvalues does:

Function s_getKeywordValues( kwdName As String) As Variant
      Dim kwdDoc As notesDocument
      Dim kwdItem As NotesItem
      
      If g_kwSysView Is Nothing Then
            s_getKeywordValues = Null
      Else
            Set kwdDoc = g_kwSysView.GetDocumentByKey(kwdName, True)
            If kwdDoc Is Nothing Then
                  s_getKeywordValues = Null
            Else
                  Set kwdItem = kwdDoc.GetFirstItem("KeywordList")
                  If kwdItem Is Nothing Then
                        s_getKeywordValues = Null
                  Else
                        s_getKeywordValues = kwdItem.Values
                  End If
            End If
      End If
End Function
0
Comment
Question by:androgyny7
  • 6
  • 3
9 Comments
 
LVL 22

Expert Comment

by:mbonaci
ID: 16760375
Hi androgyny7,
To process all values of SendTo field instead of this:

    Set nam = New NotesName(doc.GetItemValue("SendTo")(0))
    address = nam.Abbreviated
    addresses = s_getKeywordValues(address)

use something like this:

    For i = 0 to Ubound( doc.SendTo )
        Set nam = New NotesName(doc.GetItemValue("SendTo")(i))
        address = nam.Abbreviated
        addresses = ArrayAppend( addresses, s_getKeywordValues( address ) )
    Next


Hope this helps,
Marko
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16760411
androgyny7,
I suggest you to use Option Declare in your designe element's Globals - Options to force you to declare all variables.
You can make it default for all new design elements by using option "Automatically add Option Declare" in the Programmer pane properties, second tab.
It'll save you great deal of time.

Marko
0
 

Author Comment

by:androgyny7
ID: 16767089
Hi!  Thanks for your comments - the issue is that sometimes the s_getkeywordvalues isn't going to return anything and so will errror when you try to append it to an array.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:mbonaci
ID: 16767231
androgyny7,

    Dim tmpAddr, address, addresses '(this is the same as you declared each of them As Variant)

    For i = 0 to Ubound( doc.SendTo )
        Set nam = New NotesName(doc.GetItemValue("SendTo")(i))
        address = nam.Abbreviated

        tmpAddr = s_getKeywordValues( address )

        If Not tmpAddr = Null Then
            addresses = ArrayAppend( addresses, tmpAddr )
        End If

    Next


Hope this helps,
Marko
0
 

Author Comment

by:androgyny7
ID: 16767406
I had something similar in my code:
For i = 0 To Ubound( doc.SendTo )
                  Set nam = New NotesName(doc.GetItemValue("SendTo")(i))
                  address = nam.Abbreviated
                  addresslookup =  s_getKeywordValues(address)
                  If addresslookup <> Null Then
                        Forall x In addresslookup
                              contains = Instr(1, x, Place)
                              If contains > 0 Then
                                    forwardaddress = s_Right(x, Place)                        
                              End If
                        End Forall
                        addresses = Arrayappend( addresses, forwardaddress )
                  End If
                  
            Next

The problem is that if s_getkeywordvalues returns a value it will contain at least 1 value, most likely 3.  And so I get a type mismatch errror.
0
 
LVL 22

Accepted Solution

by:
mbonaci earned 1000 total points
ID: 16767501
androgyny7,
you get type mismatch because you're trying to append string to an array:

        If contains > 0 Then
            forwardaddress = s_Right(x, Place)' here you get the string?
        End If
    End Forall
    addresses = Arrayappend( addresses, forwardaddress ) ' and here you're trying to append it


It's something wrong with this part:

    Forall x In addresslookup   'here you go through all that function has returned (lets say 3 addresses)
        contains = Instr(1, x, Place)
        If contains > 0 Then
            forwardaddress = s_Right(x, Place)  'and here use only the third (always the last one) address
        End If
    End Forall
    addresses = Arrayappend( addresses, forwardaddress )



Hope this helps,
Marko
0
 

Author Comment

by:androgyny7
ID: 16767723
the code fails on the If addresslookup <> Null Then statement.  It doesnt even go into the Forall loop.
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16767886
androgyny7,
try like this:
    If Not IsNull( addresslookup ) Then

Hope this helps,
Marko
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16767900
androgyny7,
and if there's a posibility to returned data can be "" Then include IsEmpty, like this (cuz' IsEmpty can be False and IsNull True of the same variant variable - see help for details):

    If Not IsNull( addresslookup ) Then
        If Not IsEmpty( addresslookup ) Then


Hope this helps,
Marko
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question