Ctype

A

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
 
C

Chris

AXH said:
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.
 
A

AXH

Chris said:
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
 
J

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


| 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
|
|
 
C

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top