Results 1 to 7 of 7

Thread: Creating Objects

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    California
    Posts
    203

    Creating Objects

    In my program, when the user presses a start button, I create an object of an activeX.dll. During the run of the program, the user is allowed to see a form or not see a form that is part of the dll. The problem is, I need to know how to determine if I have already created the object or not.

    My code is something like this:

    Set ObjServer = CreateObject("myproject.clsMyClass")
    objServer.StartProgram


    When the clien app is loaded, this above code does not occur unless they want to start the process. However, they can just choose another button which will show a form in that DLL. the code is this


    if objserver has been set then
    Objserver.ShowLogForm
    Else
    Set ObjServer = CreateObject("MyProject.clsMyClass")
    ObjServer.ShowLogForm
    end if


    I need to know if the object was created yet?

  2. #2
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Will this work?
    VB Code:
    1. If obj = Nothing Then
    2. '    CreateObject
    3. Else
    4. 'it is already created
    5. End if
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  3. #3
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    I'm not 100% about this but.......

    I think if you use GetObject instead of CreateObject then it attempts to create an instance of an object that is already being used in memory (by any program), if this fails, then there is no instance of that object in memory so use CreateObject.

    Thats the theory anyhoo.


    darrel.
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    California
    Posts
    203
    That works. I was trying to use if obj = nothing instead of if obj IS NOTHiNG.

    Thanks alot.

    M

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    darre1 - GetObject gets the latest instance of an object/class.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    cander,

    that's exactly what i just said, only i used more words, bad english, more sentences and lots of extra bits to exercise my fingers.

    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  7. #7
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    LOL
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width