Results 1 to 7 of 7

Thread: [RESOLVED] IsObject Function

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    99

    Resolved [RESOLVED] IsObject Function

    Am currently cleaning up code in preparation for VB.Net Migration.

    Am Adding Option Explicit to my VB6 code where missing and have come across a situation I need assistance in resolving.

    Code:
    If IsObject(SomeControl) then
    Msgbox "Control Exists in this project"
    else
    Msgbox "Control does not exist in this project"
    Endif

    This code works properly to detect the existence of a control providing that I do not include Option Explicit in my code.

    If I do use Option Explicit and SomeControl does not exist in project then I get Undefined Variable error on SomeControl.

    How do I use IsObject to detect presence of object when OptionExplicit is ON?

    Lee

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: IsObject Function

    Welcome to the forums.

    There is a function in your project called IsObject, right?

    It needs to have one parameter passed to it, and that is what that code is attempting to do. It is an example. Apparently someone just copy 'n pasted the example without changing it to suit the individual needs of the project.

    My guess is that you probably don't need it anyway.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    99

    Re: IsObject Function

    IsObject is a VB6 Function

    If there is an object in the project IsObject(Objectname) wil return True.
    If ObjectName does not exist, IsObject(ObjectName) will return false.

    Exception is if Option Explicit is included in project code then ObjectName MUST be defined even though it may not exist.

    Hence, source of my confusion.

    Sample code is just to illustratete my point - not production code.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: IsObject Function

    You are misunderstanding how IsObject is supposed to be used. It is not meant to tell you if an object exists in your app because surely know if it does because you have the code in front of you. Instead it is used to tell if a Variant contains an object or not. In other words if you had a Variant called MyVar and a label and you did

    Code:
    MyVar = Label1
    MsgBox IsObject(MyVar)
    You would see "True" displayed, but if you did

    Code:
    MyVar = "test"
    MsgBox IsObject(MyVar)
    you would see "False".

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    99

    Re: IsObject Function

    Martin:
    Guess I was using it wrong for past few years.

    I have a lot of reusable code and functions in a 400,000 line project made up of 24 VBP's and 150 forms.

    I've used the IsObject to determine if a particular function or subroutine should do something specific if it's being called from within a particular project.

    So, now I'm faced with finding a method to determine which project I'm executing within. Will probably just store a global variable for Project Name.

    Thanks for clarifying this

    Lee

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: IsObject Function

    Now that we've helped you, you can help us by marking the thread as resolved. If you have JavaScript enabled you can do that easily by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. (No need to do it for me.) Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see your rating and know that you appreciate their help.

  7. #7

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