Ctype

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AXH

    #1

    Ctype

    Hi All,

    I have to following problem.
    Is it possible type convert a stringvalue to a type value.
    Please look below for the example


    dim regvalue as string= "123456"
    dim regtype as string = "String"

    private function GetValue as object
    return ctype(regvalue, ?????????)
    end function

    Thanks,
    AXH


  • Chris

    #2
    Re: Ctype

    AXH wrote:
    Hi All,
    >
    I have to following problem.
    Is it possible type convert a stringvalue to a type value.
    Please look below for the example
    >
    >
    dim regvalue as string= "123456"
    dim regtype as string = "String"
    >
    private function GetValue as object
    return ctype(regvalue, ?????????)
    end function
    >
    Thanks,
    AXH
    >
    >
    I might not have this exact as I don't have my compiler here but it's
    something like:

    return ctype(regvalue, Type.GetType(re gtype))

    of course in your example this won't do much since your function is
    returning a type object.

    Comment

    • AXH

      #3
      Re: Ctype


      "Chris" <no@spam.comwro te in message
      news:eYpU4HHwGH A.724@TK2MSFTNG P05.phx.gbl...
      AXH wrote:
      >Hi All,
      >>
      >I have to following problem.
      >Is it possible type convert a stringvalue to a type value.
      >Please look below for the example
      >>
      >>
      >dim regvalue as string= "123456"
      >dim regtype as string = "String"
      >>
      >private function GetValue as object
      > return ctype(regvalue, ?????????)
      >end function
      >>
      >Thanks,
      >AXH
      >
      I might not have this exact as I don't have my compiler here but it's
      something like:
      >
      return ctype(regvalue, Type.GetType(re gtype))
      >
      of course in your example this won't do much since your function is
      returning a type object.

      The above code isn't working oke. I will het an error.

      Anyone suggestions !!

      Thanks


      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Ctype

        AXH,
        It sounds like you want to use Convert.ChangeT ype.

        | dim regvalue as string= "123456"
        dim regtype as string = "System.Str ing"
        |
        | private function GetValue as object
        Return Convert.ChangeT ype(regvalue, Type.GetType(re gtype))
        | end function

        NOTE: regtype needs to be one of the types listed in System.TypeCode ,
        qualified with its namespace (such as System.String & System.Int32)

        Alternatively you could simply use the overload that accepted
        System.TypeCode or use GetType(String) & GetType(Integer )...

        --
        Hope this helps
        Jay B. Harlow [MVP - Outlook]
        ..NET Application Architect, Enthusiast, & Evangelist
        T.S. Bradley - http://www.tsbradley.net


        "AXH" <axhollaar@hotm ail.comwrote in message
        news:%23dKc52Fw GHA.4512@TK2MSF TNGP05.phx.gbl. ..
        | Hi All,
        |
        | I have to following problem.
        | Is it possible type convert a stringvalue to a type value.
        | Please look below for the example
        |
        |
        | dim regvalue as string= "123456"
        | dim regtype as string = "String"
        |
        | private function GetValue as object
        | return ctype(regvalue, ?????????)
        | end function
        |
        | Thanks,
        | AXH
        |
        |


        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Ctype

          AXH,

          A string is a type.

          You can set a string in an object
          dim myObject as Object = CType("12345",O bject)

          Althoug a little bit out of sence because
          dim myObject as Object = "12345" works impliciet

          I hope this helps,

          Cor


          "AXH" <axhollaar@hotm ail.comschreef in bericht
          news:%23dKc52Fw GHA.4512@TK2MSF TNGP05.phx.gbl. ..
          Hi All,
          >
          I have to following problem.
          Is it possible type convert a stringvalue to a type value.
          Please look below for the example
          >
          >
          dim regvalue as string= "123456"
          dim regtype as string = "String"
          >
          private function GetValue as object
          return ctype(regvalue, ?????????)
          end function
          >
          Thanks,
          AXH
          >

          Comment

          Working...