How to Determine If VB 4.0 App Was Launched as OLE Server (129739)



The information in this article applies to:

  • Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
  • Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
  • Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
  • Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0
  • Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0

This article was previously published under Q129739

SUMMARY

This article describes how to use the StartMode Property of the Visual Basic App object to determine whether an application started as a stand-alone project or as an OLE Automation object application.

MORE INFORMATION

If the StartMode property has a value of vbSModeStandalone (or 0), it means that the application started as a stand-alone project. That is, the user started the .EXE from File Manager or by double-clicking the icon from Program Manager.

If the StartMode property has a value of vbSModeAutomation (or 1), it means that the application started as an OLE Automation object application. That is, the .EXE started because an OLE Automation client called CreateObject.

These constants are listed in the Visual Basic object library in the Object Browser.

At design time, you can debug an application as if it were started as an OLE Automation object application by setting StartMode in the Project Options dialog box to 1 (vbSModeAutomation) by selecting the OLEServer option button. But a project's actual StartMode setting is determined by how that application is started at run time, not by its nominal setting in the Project Options dialog box when you create an executable (.EXE) file.

When StartMode is set to 1 and there are no public classes in the project, you must use the End statement or choose End from the Run menu or toolbar to end the application. If you choose Close from the Control menu, the form closes but the project is still running.

Step-by-Step Example

  1. Start a new project in Visual Basic. Form1 is created by default.
  2. Add a new Module to the project by choosing Module from the Insert menu. Module1 is created by default.
  3. Copy the following code, and Paste it into the General Declarations portion of Module1:
       Public Sub main()
          If App.StartMode = vbSModeStandalone Then
             MsgBox "Application being started as a stand alone EXE!"
          Else
             MsgBox "Application being started as an OLE Automation server!"
          End If
       End Sub
    						
  4. In the Project Options dialog box (Choose Options from the Tools menu and then select the Project tab), choose Sub Main as the startup form and choose OLEServer as the startmode.
  5. Press the F5 key to run the program. A message box will tell you that the application was started as an OLE Automation server.

Modification Type:MajorLast Reviewed:12/9/2003
Keywords:KB129739