cType function not dynamic

I am filling the rows of a datatable in a for loop and want to handle the type conversion for the different columns dynamically.  The problem I was running into is the cType function won't accept a type object as an object.  Here is the code I was trying


       Dim Val As Object
       Dim ColDataType As Type = ThisTable.Columns(CPI.PropName).DataType
       Val = CPI.EvaluatedVal(CType(objCont.Value.Obj, SldWorks.Feature), InDoc:=objCont.Value.ParentDoc)

      ThisRow.Item(CPI.PropName) = CType(Val, coldatatype)'<-------Compiler error  Type 'coldatatype' is not defined.

What is one to do?
LVL 13
Corey ScheichDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Are you using Option Strict On?

Does this work?
    ThisRow.Item(CPI.PropName) = Val

Bob

0
Corey ScheichDeveloperAuthor Commented:
With Option Strict Off when I did that it was throwing an exception when Val was returned as a numeric string and the type of the column was double.
0
Corey ScheichDeveloperAuthor Commented:
(I should add) Even when the String could be cast to a double
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Bob LearnedCommented:
First of all, Val is a reserved keyword.  If a value is an empty string, and you need to convert it to a number, there 2 choices if you don't want to get an exception:

Val(numberString)
Double.TryParse

Bob
0
Corey ScheichDeveloperAuthor Commented:
So you can't use Ctype() when you don't know the type in advance?
0
Bob LearnedCommented:
No, I don't believe that you can.  At least I wouldn't know the workaround for the correct syntax.

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LantraxCommented:
Has anyone figured this out?

I am have the same exact problem with the exact same functionality. I cna't find any solution.
0
Corey ScheichDeveloperAuthor Commented:
Lantrax,

To my knowledge you will  have to create Select case statement to handle the different type possibilities.  I think this is quite sad it would have been much more efficient to be able to use cType in this manner but it isn't possible to my knowledge.

Corey
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.