Home All Groups Group Topic Archive Search About
Author
15 Aug 2006 11:35 AM
AXH
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

Author
15 Aug 2006 1:51 PM
Chris
AXH wrote:
Show quoteHide quote
> 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(regtype))

of course in your example this won't do much since your function is
returning a type object.
Author
15 Aug 2006 9:14 PM
AXH
Show quote Hide quote
"Chris" <no@spam.com> wrote in message
news:eYpU4HHwGHA.724@TK2MSFTNGP05.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(regtype))
>
> 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
Author
15 Aug 2006 10:45 PM
Jay B. Harlow [MVP - Outlook]
AXH,
It sounds like you want to use Convert.ChangeType.

| dim regvalue as string= "123456"
    dim regtype as string = "System.String"
|
| private function GetValue as object
    Return Convert.ChangeType(regvalue, Type.GetType(regtype))
| 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


Show quoteHide quote
"AXH" <axholl***@hotmail.com> wrote in message
news:%23dKc52FwGHA.4512@TK2MSFTNGP05.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
|
|
Author
16 Aug 2006 6:59 AM
Cor Ligthert [MVP]
AXH,

A string is a type.

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

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

I hope this helps,

Cor


Show quoteHide quote
"AXH" <axholl***@hotmail.com> schreef in bericht
news:%23dKc52FwGHA.4512@TK2MSFTNGP05.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
>