.






Using OLE Servers in Visual FoxPro



Discussion

Visual FoxPro (v3.0 min) interfaces to OLE Servers in a similar manner to Visual Basic, but with slightly different syntax. Since many OLE Server examples are presented in Visual Basic, let's focus on the syntactical differences between the two. We will then be able to easily translate VB examples into Visual FoxPro syntax in the future.

As an example, two sets of code are shown below. Each one creates and sends an E-mail message through the IDSMail OLE Server:

Visual Basic v3.0 Syntax

    Dim idsMail as Object
    Set idsMail = CreateObject("IDSMailInterface.Server")
    idsMail.ObjectKey = "ABCDE12345"  
    idsMail.AddRecipientTo "Jim Stevens"
    idsMail.AddRecipientCc "Mary Brown, Doug Williams"
    idsMail.Subject = "Meeting Agenda"
    idsMail.AddAttachment "C:\MEETINGS\AGENDA.DOC"
    idsMail.Message = "Here is the agenda for this weeks meeting."
    idsMail.Send


Visual FoxPro Syntax

    Local idsMail
    idsMail = CreateObject("IDSMailInterface.Server")
    idsMail.ObjectKey = "ABC123"   
    idsMail.AddRecipientTo ("Jim Stevens")  
    idsMail.AddRecipientCc ("Mary Brown, Doug Williams")
    idsMail.AddAttachment ("C:\MEETINGS\AGENDA.DOC")
    idsMail.Subject = "Meeting Agenda"
    idsMail.Message = "Here is the agenda for the weekly meeting."
    idsMail.Send


The examples are very similar. Properties such as ObjectKey, Subject, and Message are set with identical syntax. Methods which do not accept parameters (i.e. Send) also show identical syntax.

The differences lie in the way variables are defined, and in methods which accept parameters such as AddRecipientTo. Visual FoxPro surrounds the parameters with parentheses while Visual Basic does not.

Conclusion

OLE Servers can add some incredible functionality to a Visual FoxPro project. With the prevalence of Visual Basic examples in OLE Server documentation, understanding the syntax differences between the two languages will allow quick and easy translation into Visual FoxPro.

Resources


© 1993-2004, AssurX, Inc. All Rights Reserved. Trademarks. 408-778-1376 | email: info@intuitive-data.com