Solved

CREATEOBJECT WITHIN A PROJECT

Posted on 2000-04-13
9
274 Views
Last Modified: 2012-05-04
Can you use createobject to instantiate an Object from a server class which is in the same project as the client class ? If you can, then how. (Note I do not want to use the new key word)
0
Comment
Question by:leecarroll
9 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2713794
If not why not create a Group Project and do it from there. This  will garantee it will work.
0
 

Author Comment

by:leecarroll
ID: 2713905
Adjusted points from 100 to 200
0
 

Author Comment

by:leecarroll
ID: 2713906
The two classes will live in the same component, so they can't be in a different project. (I've read that you should use createobject within a component if you are going to use mts and you wish the object to have an object context, new does not cut the mustard as it does not use com.) Is my understanding of MTS at fault here, I feel that i'm missing something. I know i've just widen the question with this comment so i'll up the points
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 15

Accepted Solution

by:
ameba earned 200 total points
ID: 2714259
You cannot do this in 'standard exe' project type.
Change project type to ActiveX EXE and then it will work.

When you change project type, you'll perhaps need 'Sub Main' for startup. In 'Sub Main' call your main form.

From VB documentation for CreateObject:
"Note   The CreateObject function cannot be used on classes whose Instancing property is Private or PublicNotCreatable. The New operator can be used on any class."
0
 
LVL 15

Expert Comment

by:ameba
ID: 2714272
Sample:
   Dim x As clsCustomer
   Set x = CreateObject("Project1.clsCustomer")
   x.Name = "John"  ' early bound call!
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2715126
"in the same project"

WHY? You're guaranteed to have a reference as it's in the same project, so just use the New keyword.

There is absolutely *NO* need to use MTS for communication between objects in the same project. Just use globals or appropriate methods and properties to achieve your goal.

Hm.... perhaps I'm missing something?
0
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 2715401
If you are using MTS, you have to use an ActiveX DLL.

MTS heavily relies on COM.

Using New to create an Object that is part of the same project will bypass COM
CreateObject always uses COM.

New will use COM if you are creating an object in a different project

0
 

Author Comment

by:leecarroll
ID: 2717707
All the comments are pretty good but Ameba got it spot on. To use Createobject the object has to be externally creatable !! Thats what i was missing.
Cheers Lee
0
 
LVL 15

Expert Comment

by:ameba
ID: 2717928
to caraf_g
>"in the same project"
>WHY?

It is good idea to start with a single project. This makes debugging easier/faster.
When things are prototyped, you can split and organize components.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

831 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