Typecasting without knowing the cast

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

    Typecasting without knowing the cast

    Hi

    I have a data row variable which could be for any of a number of tables in
    my apps. How can I type cast the variable to correct type at runtime? I know
    I can get the type description using MyRow.ToString but don't know how to
    use this to typecast MyRow variable. I need this to write a generic SUB that
    can deal with rows of any table type.

    Thanks

    Regards


  • Armin Zingler

    #2
    Re: Typecasting without knowing the cast

    "John" <info@nospam.in fovis.co.ukschr ieb
    Hi
    >
    I have a data row variable which could be for any of a number of
    tables in my apps. How can I type cast the variable to correct type
    at runtime? I know I can get the type description using
    MyRow.ToString but don't know how to use this to typecast MyRow
    variable. I need this to write a generic SUB that can deal with rows
    of any table type.
    Maybe you are looking for this:

    if typeof row is CustomerRow then
    directcast(row, CustomerRow).Me mber 'any type specific member
    elseif typeof row is contractRow then

    '...

    end if

    Type casting without knowing the destination type at design time does
    not make sense. Casting is there to be able to write code that is
    specific to a certain type. If you don't know the destination type, you
    can not write type specific code.


    Armin

    Comment

    • kimiraikkonen

      #3
      Re: Typecasting without knowing the cast

      On Apr 28, 10:31 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
      Hi
      >
      I have a data row variable which could be for any of a number of tables in
      my apps. How can I type cast the variable to correct type at runtime? I know
      I can get the type description using MyRow.ToString but don't know how to
      use this to typecast MyRow variable. I need this to write a generic SUB that
      can deal with rows of any table type.
      >
      Thanks
      >
      Regards
      John,
      To know the type of object, use GetType function to determine. Then
      maybe you'll have a change for type casting.

      Hope this helps,

      Onur

      Comment

      • Tom Shelton

        #4
        Re: Typecasting without knowing the cast

        On 2008-04-28, John <info@nospam.in fovis.co.ukwrot e:
        Hi
        >
        I have a data row variable which could be for any of a number of tables in
        my apps. How can I type cast the variable to correct type at runtime? I know
        I can get the type description using MyRow.ToString but don't know how to
        use this to typecast MyRow variable. I need this to write a generic SUB that
        can deal with rows of any table type.
        >
        Thanks
        >
        Regards
        >
        >
        Assuming that Row inherits from DataRow, then that is the type you would
        be working with.

        --
        Tom Shelton

        Comment

        • John

          #5
          Re: Typecasting without knowing the cast

          I am trying

          CType(MyRow, GetType(MyRow))

          but it says 'Error 1 Keyword does not name a type' on GetType.

          Thanks

          Regards


          "kimiraikko nen" <kimiraikkonen8 5@gmail.comwrot e in message
          news:0be0e139-0b2a-4e4b-bf00-ec6050923a70@a7 0g2000hsh.googl egroups.com...
          On Apr 28, 10:31 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
          >Hi
          >>
          >I have a data row variable which could be for any of a number of tables
          >in
          >my apps. How can I type cast the variable to correct type at runtime? I
          >know
          >I can get the type description using MyRow.ToString but don't know how to
          >use this to typecast MyRow variable. I need this to write a generic SUB
          >that
          >can deal with rows of any table type.
          >>
          >Thanks
          >>
          >Regards
          >
          John,
          To know the type of object, use GetType function to determine. Then
          maybe you'll have a change for type casting.
          >
          Hope this helps,
          >
          Onur

          Comment

          • Armin Zingler

            #6
            Re: Typecasting without knowing the cast

            "John" <info@nospam.in fovis.co.ukschr ieb
            I am trying
            >
            CType(MyRow, GetType(MyRow))
            >
            but it says 'Error 1 Keyword does not name a type' on GetType.
            Have you read my message? Why do you want to cast at all?


            Armin

            Comment

            • John

              #7
              Re: Typecasting without knowing the cast

              I am writing a library of generalised SUB to handle any table's row that the
              user using the library may need to pass to library. I do not know the actual
              type of the data row that user will be passing therefore I need to figure it
              at runtime.

              Thanks

              Regards

              "Armin Zingler" <az.nospam@free net.dewrote in message
              news:Oh95aKYqIH A.3940@TK2MSFTN GP03.phx.gbl...
              "John" <info@nospam.in fovis.co.ukschr ieb
              >I am trying
              >>
              >CType(MyRow, GetType(MyRow))
              >>
              >but it says 'Error 1 Keyword does not name a type' on GetType.
              >
              Have you read my message? Why do you want to cast at all?
              >
              >
              Armin

              Comment

              • Armin Zingler

                #8
                Re: Typecasting without knowing the cast

                "John" <info@nospam.in fovis.co.ukschr ieb
                I am writing a library of generalised SUB to handle any table's row
                that the user using the library may need to pass to library. I do
                not know the actual type of the data row that user will be passing
                therefore I need to figure it at runtime.
                Sry, I don't get it. If you don't know the actual type, how do you want
                to handle different types differently? That's a contradiction.

                If you determine the type at _runtime_, how do you want to take the type
                into account at _design time_? Design time is before runtime.


                Armin

                Comment

                • Tom Shelton

                  #9
                  Re: Typecasting without knowing the cast

                  On 2008-04-28, John <info@nospam.in fovis.co.ukwrot e:
                  I am writing a library of generalised SUB to handle any table's row that the
                  user using the library may need to pass to library. I do not know the actual
                  type of the data row that user will be passing therefore I need to figure it
                  at runtime.
                  >
                  Thanks
                  John,

                  What kind of actions are you trying to take on these rows? Basically,
                  what I'm saying, is unless you know the type or the types that can be
                  passed, then you can't get there from here....

                  Like I said, you can handle all the Rows as DataRow, and that is about
                  as close as your going to get.

                  --
                  Tom Shelton

                  Comment

                  • John

                    #10
                    Re: Typecasting without knowing the cast

                    Thanks. I know what you mean.

                    Regards

                    "Armin Zingler" <az.nospam@free net.dewrote in message
                    news:ODER3WYqIH A.4292@TK2MSFTN GP04.phx.gbl...
                    "John" <info@nospam.in fovis.co.ukschr ieb
                    >I am writing a library of generalised SUB to handle any table's row
                    >that the user using the library may need to pass to library. I do
                    >not know the actual type of the data row that user will be passing
                    >therefore I need to figure it at runtime.
                    >
                    Sry, I don't get it. If you don't know the actual type, how do you want
                    to handle different types differently? That's a contradiction.
                    >
                    If you determine the type at _runtime_, how do you want to take the type
                    into account at _design time_? Design time is before runtime.
                    >
                    >
                    Armin
                    >

                    Comment

                    • John

                      #11
                      Re: Typecasting without knowing the cast

                      Got it. Thanks

                      Regards

                      "Tom Shelton" <tom_shelton@YO UKNOWTHEDRILLco mcast.netwrote in message
                      news:%23kDDGkYq IHA.1164@TK2MSF TNGP04.phx.gbl. ..
                      On 2008-04-28, John <info@nospam.in fovis.co.ukwrot e:
                      >I am writing a library of generalised SUB to handle any table's row that
                      >the
                      >user using the library may need to pass to library. I do not know the
                      >actual
                      >type of the data row that user will be passing therefore I need to figure
                      >it
                      >at runtime.
                      >>
                      >Thanks
                      >
                      John,
                      >
                      What kind of actions are you trying to take on these rows? Basically,
                      what I'm saying, is unless you know the type or the types that can be
                      passed, then you can't get there from here....
                      >
                      Like I said, you can handle all the Rows as DataRow, and that is about
                      as close as your going to get.
                      >
                      --
                      Tom Shelton

                      Comment

                      • Cor Ligthert[MVP]

                        #12
                        Re: Typecasting without knowing the cast





                        Cor


                        "John" <info@nospam.in fovis.co.ukschr eef in bericht
                        news:OFrcnZWqIH A.3680@TK2MSFTN GP05.phx.gbl...
                        Hi
                        >
                        I have a data row variable which could be for any of a number of tables in
                        my apps. How can I type cast the variable to correct type at runtime? I
                        know I can get the type description using MyRow.ToString but don't know
                        how to use this to typecast MyRow variable. I need this to write a generic
                        SUB that can deal with rows of any table type.
                        >
                        Thanks
                        >
                        Regards
                        >

                        Comment

                        Working...