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. String to Object Question

String to Object Question

Scheduled Pinned Locked Moved Visual Basic
question
13 Posts 4 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.
  • F Offline
    F Offline
    Fahad Sadah
    wrote on last edited by
    #1

    Hello all! If an object has a member, who's name was not known but only stored in a string, how could I access that member? Thanks in advance, Fahad Sadah

    New freeware site underway!

    A N 2 Replies Last reply
    0
    • F Fahad Sadah

      Hello all! If an object has a member, who's name was not known but only stored in a string, how could I access that member? Thanks in advance, Fahad Sadah

      New freeware site underway!

      A Offline
      A Offline
      AliAmjad
      wrote on last edited by
      #2

      What you exactly mean by this question??? How come an object has a member who has no name ! and if it is then what you think intelliSense is for? and didn't understand yet what you exactly trying to ask.

      AliAmjad(MCP) First make it Run THEN make it Run Fast!

      C 1 Reply Last reply
      0
      • F Fahad Sadah

        Hello all! If an object has a member, who's name was not known but only stored in a string, how could I access that member? Thanks in advance, Fahad Sadah

        New freeware site underway!

        N Offline
        N Offline
        nlarson11
        wrote on last edited by
        #3

        sounds like your talking about reflection...

        F 1 Reply Last reply
        0
        • A AliAmjad

          What you exactly mean by this question??? How come an object has a member who has no name ! and if it is then what you think intelliSense is for? and didn't understand yet what you exactly trying to ask.

          AliAmjad(MCP) First make it Run THEN make it Run Fast!

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          AliAmjad wrote:

          How come an object has a member who has no name !

          He didn't say the object's member had no name. He said the name was stored in a string.


          Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

          A 1 Reply Last reply
          0
          • C Colin Angus Mackay

            AliAmjad wrote:

            How come an object has a member who has no name !

            He didn't say the object's member had no name. He said the name was stored in a string.


            Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

            A Offline
            A Offline
            AliAmjad
            wrote on last edited by
            #5

            Thanks for correcting me man ! but can you please explain it a bit "object has a member, who's name was not known but only stored in a string" I still don't get it.

            AliAmjad(MCP) First make it Run THEN make it Run Fast!

            F 1 Reply Last reply
            0
            • A AliAmjad

              Thanks for correcting me man ! but can you please explain it a bit "object has a member, who's name was not known but only stored in a string" I still don't get it.

              AliAmjad(MCP) First make it Run THEN make it Run Fast!

              F Offline
              F Offline
              Fahad Sadah
              wrote on last edited by
              #6

              I'll give an example: Dim obj As New MyClass Dim str As String = "member" Assume that str was user input, and I do not know what it is. How do I access obj.str?

              A 1 Reply Last reply
              0
              • N nlarson11

                sounds like your talking about reflection...

                F Offline
                F Offline
                Fahad Sadah
                wrote on last edited by
                #7

                Pardon the noobish question please: whats reflection?

                C 1 Reply Last reply
                0
                • F Fahad Sadah

                  I'll give an example: Dim obj As New MyClass Dim str As String = "member" Assume that str was user input, and I do not know what it is. How do I access obj.str?

                  A Offline
                  A Offline
                  AliAmjad
                  wrote on last edited by
                  #8

                  Are you saying that user knew the method in your Class and you want to choose the method in your MyClass according to what user enters ???

                  Fahad Sadah wrote:

                  How do I access obj.str?

                  str is not even a member of MyClass its just a string field which can be used at class level or in a method locally depends on its declaration.

                  AliAmjad(MCP) First make it Run THEN make it Run Fast!

                  C 1 Reply Last reply
                  0
                  • A AliAmjad

                    Are you saying that user knew the method in your Class and you want to choose the method in your MyClass according to what user enters ???

                    Fahad Sadah wrote:

                    How do I access obj.str?

                    str is not even a member of MyClass its just a string field which can be used at class level or in a method locally depends on its declaration.

                    AliAmjad(MCP) First make it Run THEN make it Run Fast!

                    C Offline
                    C Offline
                    Colin Angus Mackay
                    wrote on last edited by
                    #9

                    AliAmjad wrote:

                    Are you saying that user knew the method in your Class and you want to choose the method in your MyClass according to what user enters ???

                    Or maybe the user knows something from which a lookup in a database or XML file could be made which returns the name of the method.

                    AliAmjad wrote:

                    str is not even a member of MyClass

                    True, you cannot use a string in that way. But you can use the string to invoke the correct method through "Reflection"


                    Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

                    A 1 Reply Last reply
                    0
                    • F Fahad Sadah

                      Pardon the noobish question please: whats reflection?

                      C Offline
                      C Offline
                      Colin Angus Mackay
                      wrote on last edited by
                      #10

                      Fahad Sadah wrote:

                      whats reflection?

                      There is a System.Reflection namespace that contains a number of useful classes to help you with this. Everything has a GetType() method which returns a Type object. Use GetMethod() to find the method that you want with the string. This will return a MethodInfo object. You can then use the MethodInfo object with your object to Invoke() the method.


                      Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

                      1 Reply Last reply
                      0
                      • C Colin Angus Mackay

                        AliAmjad wrote:

                        Are you saying that user knew the method in your Class and you want to choose the method in your MyClass according to what user enters ???

                        Or maybe the user knows something from which a lookup in a database or XML file could be made which returns the name of the method.

                        AliAmjad wrote:

                        str is not even a member of MyClass

                        True, you cannot use a string in that way. But you can use the string to invoke the correct method through "Reflection"


                        Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

                        A Offline
                        A Offline
                        AliAmjad
                        wrote on last edited by
                        #11

                        I know buddy but as he said in his later post bellow that he's a newbie didn't know anything about reflection so thought that he didn't ask a question related to reflection !

                        AliAmjad(MCP) First make it Run THEN make it Run Fast!

                        C 1 Reply Last reply
                        0
                        • A AliAmjad

                          I know buddy but as he said in his later post bellow that he's a newbie didn't know anything about reflection so thought that he didn't ask a question related to reflection !

                          AliAmjad(MCP) First make it Run THEN make it Run Fast!

                          C Offline
                          C Offline
                          Colin Angus Mackay
                          wrote on last edited by
                          #12

                          AliAmjad wrote:

                          I know buddy but as he said in his later post bellow that he's a newbie didn't know anything about reflection so thought that he didn't ask a question related to reflection !

                          Why would you think that? The most obvious thing is that if he didn't know anything about reflection then his question may be related but he didn't realise it was related. It is therefore necessary to bring the idea to his attention to find out if it really is related or not.


                          Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

                          A 1 Reply Last reply
                          0
                          • C Colin Angus Mackay

                            AliAmjad wrote:

                            I know buddy but as he said in his later post bellow that he's a newbie didn't know anything about reflection so thought that he didn't ask a question related to reflection !

                            Why would you think that? The most obvious thing is that if he didn't know anything about reflection then his question may be related but he didn't realise it was related. It is therefore necessary to bring the idea to his attention to find out if it really is related or not.


                            Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

                            A Offline
                            A Offline
                            AliAmjad
                            wrote on last edited by
                            #13

                            Ok Thank you very much for bringing this aspect to my attention. It was quite a nice learning experience for me. Thanks !

                            AliAmjad(MCP) First make it Run THEN make it Run Fast!

                            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