Solved

Create Object & New Function

Posted on 2002-04-26
4
144 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses
Course of the Month4 days, 9 hours left to enroll

636 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