|
-
Sep 26th, 2002, 03:11 PM
#1
Thread Starter
Addicted Member
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
-
Sep 26th, 2002, 03:14 PM
#2
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)
-
Sep 26th, 2002, 03:16 PM
#3
Addicted Member
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
-
Sep 26th, 2002, 03:18 PM
#4
Thread Starter
Addicted Member
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
-
Sep 26th, 2002, 06:56 PM
#5
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)
-
Sep 30th, 2002, 11:21 AM
#6
Addicted Member
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)
-
Sep 30th, 2002, 11:27 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|