Results 1 to 5 of 5

Thread: [RESOLVED] Has object already been set?

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Resolved [RESOLVED] Has object already been set?

    How can I check to see if an object has been set or not?
    I have this code in my form, that relates to a class (I can post if needed), but if the object has already been set I obviously get an error.
    Code:
    Set oPic = New CMDIPicture
    
         'The Init method takes the MDI form and a standard picture object
         'as argument. Instead of LoadPicture you can pass the Picture property of
         'any PictureBox or Image control or Load an image from a resource file.
                
    oPic.Init MDIMain, LoadPicture(App.Path & "\Image.jpg")
    I just don't know how to check before I run this code.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2
    Lively Member
    Join Date
    Aug 2005
    Posts
    126

    Re: Has object already been set?

    If oPic = Null Then

    Else
    --Already initialized
    End If

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Has object already been set?

    That will give an error if the object is not set ("object not set"), and even if it is ("...invalid assignment").

    The correct method is to use "Is Nothing":
    Code:
    If oPic Is Nothing Then 
      Set oPic = New CMDIPicture
    Else
      'already set
    End If

  4. #4

  5. #5

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Has object already been set?

    Thanks all, I will give this a go.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

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