Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Why isn't this working ?

Dim x As Integer = 90
 Dim temp As Object
 Dim typ As Type = Type.GetType("System.String")
 temp = CType(x, Typ)


It shows error in 2nd argument of Ctype function. :doh:
Posted

1 solution

CType gives the error because there is no valid conversion between x (Integer) and typ(Type!!!). You would want to use CType(x, String) or even CType(x, Object).
Anyhow why not use x.ToString()?

Cheers
 
Share this answer
 
Comments
Dan Suthar 15-Jul-10 10:25am    
by the way it shouldn't be invalid as we can always convert int to string my friend. And by using this way , i want to make it dynamic , so lets say by typing the STRING NAME of any type we can convert the target to it or not?

I can always use CType(x, String) or x.ToString() but that will make me fix at a particular type cast at compile time. I want to do that at run time , say depending upon the user choice. Any help will great .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900