Re: Assigning a 'type' to a variable at runtime

Tech-Archive recommends: Fix windows errors by optimizing your registry



JohnR,

We see this more in this newsgroup and than I think forever, what will be
the use of this solution. It sounds for me as throwing apples and pears in
one container and than split them again afterwards. Why not direct in two
containers. That will probably keep the taste of the apples and the pears
much better.

Can you explain to us what is your reason behind this question?

(That container withouth telling what it is, is of couse 'object').

Cor


"JohnR" <JohnR104@xxxxxxxxxxx> schreef in bericht
news:RqH2f.9102$tU1.1605@xxxxxxxxxxx
> I'm trying to find a way to create a variable of a given type at runtime
> where I won't know the type until it actually executes. For example,
>
> dim x as object = "hi"
>
> x is declared as an object but x.gettype returns 'string', so it knows it
> contains a string.
>
> If I want to create a variable "y" as the same type that variable x
> contains how would I do that without having to iterate thru every possible
> type? That is, for the above example I would want the equivalent of "dim
> y as string" because x.gettype is string. Another example:
>
> dim x as object = new MyClass
>
> x.gettype would return 'MyClass' so I would want the equivalent of "dim y
> as myclass".
>
> Although it's not legal to do this "Dim y as x.gettype.name" that is
> exactly what I want to do.
>
> Is there anyway to accomplish this?
>
> Thanks, John
>


.



Relevant Pages

  • Re: how do you pass string value from a form to class
    ... >no the string value in the from is hard set ... >Dim MyClass As OutAddIn ...
    (microsoft.public.vb.general.discussion)
  • Re: String and Class
    ... I have a class, named MyClass, with 2 properties: ... And I have a string as follows: "dog, new york, france, car" ... Dim myList As ArrayList ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Casting from interface to its base type
    ... Dim _myClass as New MyClass(of String) ... For each _kvp as KeyPairValue(of String, IMyInterface) ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Casting from interface to its base type
    ... Dim _myClass as New MyClass(of String) ... For each _kvp as KeyPairValue(of String, IMyInterface) ...
    (microsoft.public.dotnet.languages.vb)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)