Solved

Create Object & New Function

Posted on 2002-04-26
4
143 Views
Last Modified: 2010-05-18
I used to develop my app. using VB6,COM,DCOM to create DLL file for my applicatoin .
  i want to know what is the different between

set Obj=CREATEOBJECT("Project.class") and
set Obj=NEW "Project.class"
also i want to know whitch is better?
Thans
Ahmed
0
Comment
Question by:ahmedali
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 100 total points
ID: 6972842
Hello

  Use New for early bind, and CreateObject to late binding

  and of course, early binding is faster
use new when u want to declare the variable as specific class ID,
but you for declaring the variable as object or variant use CreateObject

0
 
LVL 15

Expert Comment

by:ameba
ID: 6972967
(from book: "Effective Visual Basic")
"The New operator is a little bit faster than the CreateObject function because the client application doesn't need to resolve the ProgID to a CLSID at run-time. When you use the New operator, VB also provides a compile-time type check on the name of the class you're using to create the object. However, when you use the CreateObject function, VB cannot verify whether the ProgID is valid at compile-time because it's merely a string argument. This means you won't know whether you have a bad ProgID until you run your code.

On the other hand, the CreateObject function can offer a little more flexibility than New does. This is because you don't have to commit to a specific CLSID at compile-time. It's not that difficult to devise a design in which a client application dynamically chooses one ProgID from a set of compatible components at run-time. This is a great option when you'd like to design an application in terms of plug-compatible components."
----

Note that CreateObject works with early bound variables.

    Dim x As IPage     ' early bound variable
    If someCondition Then
        Set x = CreateObject("YourPlugIn.clsPage")
    Else
        Set x = CreateObject("YourPlugIn.clsNicePage")
    End If
    x.Show   ' early bound call (very fast)

and New works with late bound variables.

    Dim y As Object      ' late binding
    If someCondition Then
        Set y = New frmProducts
    Else
        Set y = New frmCustomers
    End If
    y.Show  ' late bound call (slow)
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7670311
Hi ahmedali,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept mnasman's comment(s) as an answer.

ahmedali, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8092626
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

728 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