Solved

CREATEOBJECT WITHIN A PROJECT

Posted on 2000-04-13
9
270 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
Comment Utility
If not why not create a Group Project and do it from there. This  will garantee it will work.
0
 

Author Comment

by:leecarroll
Comment Utility
Adjusted points from 100 to 200
0
 

Author Comment

by:leecarroll
Comment Utility
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
 
LVL 15

Accepted Solution

by:
ameba earned 200 total points
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 15

Expert Comment

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

Expert Comment

by:caraf_g
Comment Utility
"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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now