make a classname a variable

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

    #1

    make a classname a variable

    Since there is no eval function in VB, is there a way to make a classname a variable? For example;

    Dim MyClassInstance 1 As New MyClass

    Dim somestring as System.String = "MyClassInstanc e1"
    "somestring".so meproperty = "somevalue"


    ....which would set MyClassInstance 1.someproperty to "somevalue"


  • Andy Gaskell

    #2
    Re: make a classname a variable

    MyClassInstance 1.GetType().Nam e

    Or if you want to make a property:

    Public ReadOnly Property ClassName() As String
    Get
    ClassName = Me.GetType().Na me
    End Get
    End Property


    "Stephen Travis" <stravis@iname. com> wrote in message
    news:uwzN2fEQEH A.1276@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Since there is no eval function in VB, is there a way to make a classname[/color]
    a variable? For example;[color=blue]
    >
    > Dim MyClassInstance 1 As New MyClass
    >
    > Dim somestring as System.String = "MyClassInstanc e1"
    > "somestring".so meproperty = "somevalue"
    >
    >
    > ...which would set MyClassInstance 1.someproperty to "somevalue"
    >
    >[/color]


    Comment

    • Frank Eller [MVP]

      #3
      Re: make a classname a variable

      Hi Stephen,
      [color=blue]
      > Since there is no eval function in VB, is there a way to make a
      > classname a variable? For example;
      >
      > Dim MyClassInstance 1 As New MyClass
      >
      > Dim somestring as System.String = "MyClassInstanc e1"
      > "somestring".so meproperty = "somevalue"
      >[/color]

      Doesn't work that way. You should use Reflection instead, look at the
      classes in the System.Reflecti on Namespace. It's a bit too complex to be
      explained here ...

      Regards,

      Frank Eller
      another blog about programming with all things related to .NET



      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: make a classname a variable

        * "Stephen Travis" <stravis@iname. com> scripsit:[color=blue]
        > Since there is no eval function in VB, is there a way to make a classname a variable? For example;
        >
        > Dim MyClassInstance 1 As New MyClass
        >
        > Dim somestring as System.String = "MyClassInstanc e1"
        > "somestring".so meproperty = "somevalue"[/color]

        See:

        <URL:http://groups.google.d e/groups?selm=c78 n0i%2411kno%241 %40ID-208219.news.uni-berlin.de>

        --
        Herfried K. Wagner [MVP]
        <URL:http://dotnet.mvps.org/>

        Comment

        Working...