Results 1 to 7 of 7

Thread: Object Comparisons

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Westminster, Md.
    Posts
    163

    Object Comparisons

    I'm in a class....

    and I'm accepting an argument that is an object which is to be processed. However if it's anything other than the type of object I'm expecting (another class) obviously I'm not going to be able to pull the data off of it that i need to process.

    You can't do this...
    if object1=typename then

    Because it says that the type is a type in System.Types and can't be used in an expresion.

    So, my question is, how do you compare objects?


    Eiredrake

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can use getType, TypeName, or probably IS ObjectType.

    Wouldn't it be easier to just make the parameter the class/object you are expecting instead of the generic object?

    Public Sub Test(Obj as MyObject)

  3. #3
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245

    Re: Object Comparisons

    Originally posted by Eiredrake
    I'm in a class....

    and I'm accepting an argument that is an object which is to be processed. However if it's anything other than the type of object I'm expecting (another class) obviously I'm not going to be able to pull the data off of it that i need to process.

    You can't do this...
    if object1=typename then

    Because it says that the type is a type in System.Types and can't be used in an expresion.

    So, my question is, how do you compare objects?


    Eiredrake
    The GetType method might work for you: Object.GetType
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Westminster, Md.
    Posts
    163

    Stumbled

    I stumbled across the IS operator. Thanks


    Actually... the problem is that I don't know what the object is before I get it. I'm storing a serialized object in the Dbase because it will hold information access information for a service. One service may require, domain name/username/password, another may require just username/password... yet another may require nothing at all.

    That's actually what I'm testing for... to make sure the object ISN'T a generic object but is actually a previously defined service class.


    Personally I think this is all stupid the way my boss wants this done. We're basically turning a relational database into an object oriented one just because he doesn't know what he wants to store. <sigh>


    Eiredrake

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    what you want to do is creat to subs/function of the same name..but differnt parameters...the program will know which one to run


    public sub login(name as string, username as string, password as string)

    public sub login(username as string, password as string)
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    Originally posted by Cander
    what you want to do is creat to subs/function of the same name..but differnt parameters...the program will know which one to run


    public sub login(name as string, username as string, password as string)

    public sub login(username as string, password as string)
    Don't forget to use the Overloads keyword.

    Public Overloads Sub login(name as string, username as string, password as string)

    Public Overloads Sub login(username as string, password as string)
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Do you use the overloads keyword Sheppe? I never do, maybe thats bad I don't know, but I just skip it. I did the same thing with the Call keyword in VB6. As long as none of them use the Overloads keyword it'll still work.

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