HOWTO: Walking the Fields Collection of a Message in Active Msg

Last reviewed: October 23, 1997
Article ID: Q175432
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0, 5.0a on the following platform: Win95

SUMMARY

Many FoxPro developers may not be aware that the Active Messaging library exists for them to use as an extremely robust alternative to canned mail messaging API (MAPI) controls. This article is designed as part of a short (non-interdependent) series intended to provide FoxPro developers with information, development tips, and useful snippets about the Microsoft Active Messaging Library.

This article introduces some aspects of working with a Message objects Fields Collection by providing a short code snippet demonstrating how to cycle through the Fields Collection of a sample Message.

MORE INFORMATION

Cycling through the fields collection can be particularly useful when trying to debug a Messaging application. This is especially true if this method is built upon to allow walking the collections of two different messages simultaneously and finding the differences between them.

   * AM_FieldData.PRG
   * ----------------
   *
   *Create a MAPI Session object then Logon. The Logon dialog can be
   *bypassed by providing a valid ProfileName as the first parameter
   *(as a string) to the Logon Method as seen below.
   objSession = CREATEOBJECT("mapi.session")
   objSession.Logon("Stevekl")

   *Get a sample message - for this example we'll take whatever is at
   *the top of the Inbox
   objMessage = objSession.Inbox.Messages.GetFirst
   objFieldsColl = objMessage.Fields

   *A key component of a Message Object is it's Fields Collection. The
   *Fields Collection is composed of a variable number of Field Objects
   *that each possess the properties: Name, Value, Type, and ID
   intFldCnt = objFieldsColl.Count
   ctrThisField = 1
   FOR ctrThisField =1 TO intFldCnt
      *Display Name, Value, Type, and ID properties of the Field Object
      DO CASE
         CASE TYPE("objFieldsColl.Item(ctrThisField).Value") = "C"
            strValue = objFieldsColl.Item(ctrThisField).Value
         CASE TYPE("objFieldsColl.Item(ctrThisField).Value") = "N"
            strValue = ;
               ALLTRIM(STR(objFieldsColl.Item(ctrThisField).Value,30,10))
         OTHERWISE
            *There is a potential that a field may contain data types
            *not support for display by Visual FoxPro.
            strValue = "Not Displayed"
      ENDCASE
      MESSAGEBOX(;
         "Field #" + ALLTRIM(STR(ctrThisField)) + " of " ;
         +    ALLTRIM(STR(intFldCnt)) ;
         +    CHR(13) + CHR(10) ;
         + "Name : " ;
         +    objFieldsColl.Item(ctrThisField).Name ;
         +    CHR(13) + CHR(10) ;
         + "Value: " ;
         +    strValue ;
         +    CHR(13) + CHR(10) ;
         + "Type : " ;
         +    ALLTRIM(STR(objFieldsColl.Item(ctrThisField).Type)) ;
         +    CHR(13)+CHR(10) ;
         + "ID   : " ;
         +    ALLTRIM(STR(objFieldsColl.Item(ctrThisField).ID,20)))
   NEXT ctrThisField

   *Clean up then exit
   objSession.Logoff
   RELEASE objFieldsColl, objMessage, objSession

REFERENCES

For additional information on where to acquire the Active Messaging library, see the following information in the Microsoft KnowledgeBase:

   ARTICLE-ID: Q171440
   TITLE     : Where to Acquire the Active Messaging Library


Further generic information on Active Messaging can be found on the MSDN, or in the OLEMSG.HLP file, which can be had by following the directions in Q171440 noted above.


Additional query words: VFoxWin
Keywords : vfoxwin ActMsg kbcode
Version : WINDOWS:3.0,3.0b,5.0,5.0a
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 23, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.