Assigning
-
Hello, I am trying to assign a class to another whose types are different. (please do not say ctype, it will not work) Consider that the following class below public Class time public hour as byte public minute as byte public second as byte end class I want to assign a DATE to this class e.g dim i as new Time i = Today.Now 'Time=Date When I do that, I want the compiler to call a method, which will allow this conversation e.g Sub A_Sub(value as object) if typeof value is date then me.hour = value.hour me.minute = value.minute me.second = value.second end if end Sub How can I do that? I think i need to use ExpandableObjectConverter class but not sure Please help Thank you Best Regards Emre YAZICI
-
Hello, I am trying to assign a class to another whose types are different. (please do not say ctype, it will not work) Consider that the following class below public Class time public hour as byte public minute as byte public second as byte end class I want to assign a DATE to this class e.g dim i as new Time i = Today.Now 'Time=Date When I do that, I want the compiler to call a method, which will allow this conversation e.g Sub A_Sub(value as object) if typeof value is date then me.hour = value.hour me.minute = value.minute me.second = value.second end if end Sub How can I do that? I think i need to use ExpandableObjectConverter class but not sure Please help Thank you Best Regards Emre YAZICI
Apparently, VB.NET does not allow operator overloading ( C# does ). That's what google told me, anyhow. Operator overloading is the facility you need to do what you're trying to do here. If VB.NET does support it, please let me know, because otherwise, I'm going to tell every person who tells me VB.NET is the same as C# that this is one more thing that C# does and VB.NET doesn't. I hope for your sake I am wrong, because without it, you're basically screwed. Christian Graus - Microsoft MVP - C++
-
Hello, I am trying to assign a class to another whose types are different. (please do not say ctype, it will not work) Consider that the following class below public Class time public hour as byte public minute as byte public second as byte end class I want to assign a DATE to this class e.g dim i as new Time i = Today.Now 'Time=Date When I do that, I want the compiler to call a method, which will allow this conversation e.g Sub A_Sub(value as object) if typeof value is date then me.hour = value.hour me.minute = value.minute me.second = value.second end if end Sub How can I do that? I think i need to use ExpandableObjectConverter class but not sure Please help Thank you Best Regards Emre YAZICI
Christian is, grudingly, correct. VB.NET 2002 and 2003 don't support operator overloading, which is what your trying to do. This is no longer a problem in 2005. The are ways around this little issue though, such as:
Public Class myTime
Private hour As Byte
Private minute As Byte
Private second As Byte
Public Sub New(ByVal value As Date)
Me.hour = value.Hour
Me.minute = value.Minute
Me.Second = value.Second
End Sub
End ClassDim i As myTime(Date.Now())
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome