Solved

CREATEOBJECT WITHIN A PROJECT

Posted on 2000-04-13
9
275 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

828 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