.






Using OLE Servers in Visual Basic 3.0



Introduction

I remember meeting with some of the editors from Visual Basic Programmer's Journal a few months ago. They said that even though VB4 was out, interest in VB3 was still hot. And why not? VB3 is still a great development environment. And, it supports OLE Servers with very few problems.

Discussion

Coding to use OLE Servers from VB3 is very similar to using a VBX control. OLE Servers have properties and methods just like VBX's. The only real difference is how you include an OLE Server in your project - you don't!

When you want to use a VBX control, you load it into your project and drop it on a form. To use an OLE Server, you just write a few lines of code like this:

    Dim idsMail as Object
    Set idsMail = CreateObject("IDSMailInterface.Server")


The CreateObject keyword starts up the server that you specify. In this case, we're using a server called IDSMail that provides universal E-mail send/receive capabilities. The string "IDSMailInterface.Server" is called the Programmatic ID of the server. Excel, Word, Visio, etc. each have their own unique programmatic id's.

Now that you've done that, you can access the OLE Server just like a VBX:

    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


Looks familiar, right?

Limitations & Workarounds

Passing Arrays

VB3 was developed to support an early version of OLE. That is not really a problem except when the OLE Server requires you to pass it an array. VB3 doesn't support this.

Most OLE Servers that pass arrays also provide an alternative method that can be used instead. For example, the IDSMail OLE Server has a method called GetHeaderItems which returns an array of E-mail message header items such as subject, date, from, etc. From VB4, it would be called like this:

    idsMail.GetHeaderItems IDSM_ITM_SUBJECT%, theSubjects$(), theCount%


And all the subjects from all the mail messages would be returned in theSubjects$(). From VB3, we would use the alternative GetHeaderItemString method instead like this:

    idsMail.MessageIndex = 1
    singleSubject$ = idsMail.GetHeaderItemString (IDSM_ITM_SUBJECT%)

which would return the subject of a single message. To get all of the subjects, we would loop through for all the messages, getting the subjects one at a time. Not a big deal.

Starting the Server

For some unknown reason, I sometimes get an error when starting the OLE Server for the first time. My motto has always been that if at first you don't succeed, try, try, again. You can download a VB3 function that does this from the resources section below.

Conclusion

OLE Servers can add some incredible functionality to a VB3 project. And your code will be fully compatible with VB4 should you decide to upgrade someday. So start coding some cool stuff!

Resources


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