Microsoft KB Archive/143040

= How to Call a Visual Basic 4.0 OLE Server from Project 4.0 =

Article ID: 143040

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Enterprise Edition

-



This article was previously published under Q143040



SUMMARY
Visual Basic 4.0 allows you to build OLE Servers, and to build applications that can use them. These calling applications are also referred to as containers. Microsoft Project 4.0 is an OLE Automation Client application; therefore it can be used to call methods and properties from OLE servers created with Visual Basic 4.0. This article describes the process of using OLE servers created by Visual Basic 4.0 with Project 4.0. The example uses the OLE server example created in the following Microsoft Knowledge Base article:

129801 How to Create and Use a Minimal OLE Automation Server



MORE INFORMATION
Prior to following this example, make sure you have built the OLE Server discussed in 129801 and have created an EXE file.

Steps to Use a Visual Basic 4.0 OLE Server with Project 4.0
 Start Project 4.0 with the default project, Project1. Select Project's Tools menu and choose the Macro item from this menu. The Macros dialog will then appear. From the Macros dialog box, select the New button. The New Macro dialog box will appear with a default name of Macro1. Select OK. Now select Project's Tools menu and choose the References item. This will bring up the References dialog box. From the References dialog box, select the browse button. This will bring up the Browse dialog box. In the FileName section of the browse dialog box, change the listings to *.EXE. This will allow us to look for our OLE Server we have already created as an executable file. Use the dialog box to move to the drive and directory containing the OLE server and select it. Then select the OK button.</li> Now you will see Project1 in the Available References box in the References dialog. Project1 should be checked, if it is not then select it. Once you confirm Project1 is in the list and checked, click OK. You now have a reference to the OLE server in Project.</li>  Place the following code into the macro. Dim MyObj As Object

Set MyObj = CreateObject("Project1.Class1")

MsgBox MyObj.MyString MsgBox MyObj.MyFunction

Set MyObj = Nothing Note the parentheses following the line MsgBox MyObj.Myfunction. The parentheses are not required when calling an OLE Server from Visual Basic 4.0, but they are required when you call an OLE Server from Project 4.0. </li> Now select Project's Run menu and select the Start item. When this subroutine executes, you will get two message boxes. The first one will say "Life is like a box of chocolates." and the second one will say "You never know what you're gonna get."</li></ol>

Additional query words: 4.00 vb4win

Keywords: KB143040

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.