G
Guest
I have a variable and a data-type string stored in a database. I need to
dynamically cast the variable to the datatype at run-time. I am able to
create the Type from the data-type string, but I am not able to cast it
correctly. Here is an example of my code, although realize that I would need
to accomplish this with any type (Boolean, Guid, String, Integer...), and not
just GUID:
Dim typeStr as String = "System.GUID"
Dim myType As Type = Type.GetType(typeStr, True, True)
Dim varStr as String = "81db359d-a970-4247-89f8-67995412da35"
'this is the code that does not work. myType gets underlined in blue,
saying "Type 'tmpType' is not defined."
varStr = CType(varStr, myType)
dynamically cast the variable to the datatype at run-time. I am able to
create the Type from the data-type string, but I am not able to cast it
correctly. Here is an example of my code, although realize that I would need
to accomplish this with any type (Boolean, Guid, String, Integer...), and not
just GUID:
Dim typeStr as String = "System.GUID"
Dim myType As Type = Type.GetType(typeStr, True, True)
Dim varStr as String = "81db359d-a970-4247-89f8-67995412da35"
'this is the code that does not work. myType gets underlined in blue,
saying "Type 'tmpType' is not defined."
varStr = CType(varStr, myType)