|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
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 AXH wrote:
Show quoteHide quote > Hi All, I might not have this exact as I don't have my compiler here but it's > > 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 > > 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.
Show quote
Hide quote
"Chris" <no@spam.com> wrote in message The above code isn't working oke. I will het an error.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. Anyone suggestions !! Thanks AXH,
It sounds like you want to use Convert.ChangeType. | dim regvalue as string= "123456" dim regtype as string = "System.String"| Return Convert.ChangeType(regvalue, Type.GetType(regtype))| private function GetValue as object | 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)... -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "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 | | 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 >
Waiting for process end , how?
Viewing machine data source names Label changes not being reflected until loop is done Fill up string array with random characters? Dim DBh as new DBhandler vb.net 2.0 question Draw Line in a specific picturebox hard drive type HelpWriter Forcing page.ispostback to run... Disappearing form in VB.net |
|||||||||||||||||||||||