Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Assigning

Assigning

Scheduled Pinned Locked Moved Visual Basic
questionhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    THEMYTH
    wrote on last edited by
    #1

    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

    C D 2 Replies Last reply
    0
    • T THEMYTH

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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++

      1 Reply Last reply
      0
      • T THEMYTH

        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

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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 Class

        Dim i As myTime(Date.Now())

        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups