Solved

Object Instancing...

Posted on 2003-12-10
11
487 Views
Last Modified: 2013-11-25
I'm wanting to write an object that behaves like MS Outlook in that when I go to get a refrence to it, if it's already running it will return the running instance. Is this possible in VB? Would or Could I do this as an ActiveX Exe project?

Dim MyObject as MyObject
Set MyObject = new MyObject
'if the object is already running, I want the currently running instance. So, theoretically I might have several refrences to it.
Any Ideas?
0
Comment
Question by:Bilbo_Baggins2
  • 5
  • 5
11 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 9915303
Hi Bilbo_Baggins2:
> Would or Could I do this as an ActiveX Exe project?
Yes

Dabas
0
 

Author Comment

by:Bilbo_Baggins2
ID: 9915655
I wrote a test program... I have one property that's a string. I want to set the property in the first instance then see that string when I read the property in each new Standard EXE instance I start. The test below doesn't work right. It's starting a new instance of clsTest each time I spawn it in the standard EXE. How do I get it to return the instance of the already running class?

The ActiveX Exe project is named clsTest and has the following code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private sName As String

Public Property Get NameOfInstance() As Variant
    NameOfInstance = sName
End Property

Public Property Let NameOfInstance(ByVal vNewValue As Variant)
    sName = vNewValue
End Property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

The Standard Exe project has the following code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim oTest As clsTest.clsTesting

Private Sub Command1_Click()
    oTest.NameOfInstance = "Jeff"
End Sub

Private Sub Command2_Click()
    Label1 = oTest.NameOfInstance
End Sub
'also tried createobject
Private Sub Form_Load()
    Set oTest = New clsTest.clsTesting
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9916039
Bilbo_Baggins2:
Is the ActiveX Exe program running in the background?

Dabas
0
 

Author Comment

by:Bilbo_Baggins2
ID: 9916277
>Is the ActiveX Exe program running in the background?

Yes, it's running in the background. When the first Standard exe starts it starts the ActiveX Exe if it isn't running yet.

Although the code above will start the ActiveX Exe.
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9916352
Bilbo_Baggins2:
What does the instancing property for the project show?

Dabas
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Bilbo_Baggins2
ID: 9916380
5 - MultiUse
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9916449
Bilbo_Baggins2:
Try to change to GlobalSingleUse

IF that fails, then try one of the other settings

Dabas
0
 

Author Comment

by:Bilbo_Baggins2
ID: 9916544
that doesn't seem to work either. It still seems to be creating each new one as a new instance.
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 400 total points
ID: 9916673
You need to add your ActiveX EXE into the ROT (Running Object Table).  This sample shows you how to do that:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=12319&lngWId=1
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9917102
Bilbo_Baggins2:
I leave you in Azra's very capable hands!

Dabas
0
 

Author Comment

by:Bilbo_Baggins2
ID: 9917555
Thanks Azra. That's exactly what I needed.

And thanks to you, Dabas. I appreciate the effort!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vb.net 2008 2 56
Question about INSTR  - need to extract data MS ACCESS query 6 54
How to compare ms sql hashbytes results within vb6 5 55
Help me. 3 48
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now