473,379 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Late bound type conversion

Hello all:

I have a list of values from a database table, each of which is
identified by name and by type, thus:

ValueField TypeName
---------- --------
"Value1" "String"
"Value2" "Boolean"
"Value3" "Integer"

In the application, these values are being put into an array of
objects, thus:

Dim obj() as Object = {"Value1","Value2","Value3"}

I would like to perform a type conversion on each object in the array,
without using a Case statement to do so. However, if I try something
like:

Dim lType as Type = Type.GetType("String")

I am not then able to do:

obj(0) = CType(obj(0),lType)

since the CType function requires an actual type, and will not accept a
variable name.

Suggestions?

Thanks much,
zdrakec

Nov 21 '05 #1
5 959
"zdrakec" <zd*****@yahoo.com> schrieb:
I am not then able to do:

obj(0) = CType(obj(0),lType)

since the CType function requires an actual type, and will not accept a
variable name.


Take a look at 'Convert.ChangeType'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #2
Thank you sir!!!!

Cheers,
zdrakec

Nov 21 '05 #3
Ah, what if the typename is actually an array of types, that is,
instead of "String", I have, "String()" ?

Thanks again,
zdrakec

Nov 21 '05 #4
"zdrakec" <zd*****@yahoo.com> schrieb:
Ah, what if the typename is actually an array of types, that is,
instead of "String", I have, "String()" ?


You'll have to iterate over the array's items and perform the conversion for
each item.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
Yes, I had already come to that conclusion :)

Thank you sir!!

Cheers,
zdrakec

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: William Ryan | last post by:
In a nutshell, I need to get the name of the object that was just pressed (in this case, the object will be a radioButton). I want to write one handler for all four radio buttons and branch off...
2
by: Steve Jorgensen | last post by:
I frequently find myself wanting to use class abstraction in VB/VBA code, and frankly, with the tacked-on class support in VB/VBA, there are some problems with trying to do that and have any...
0
by: Matt | last post by:
I'm trying to use late binding to automate Excel from C# so as to run with multiple versions of Excel, and am hoping to avoid referencing any Excel PIA in my project. But I need to add a C# event...
9
by: Scott English | last post by:
I am writing an C# program. I call a method on a COM object that returns Object. I don't know the type of the object (and reflection just says its a __ComObject), but I know there is supposed to...
2
by: hazz | last post by:
how do I do this? I am certain my Visual Studio .NET solution allowed me to do this before but I don't know how the build/debug settings were configured. In order to get around an unavoidable...
1
by: Daniel | last post by:
How do I call a delegate in late bound C# dll? there some way to do this w/ a sharedinterface file? any examples? i tried this but it doesnt work: (oType.GetMethod("IOCTLJOB").Invoke(pObj, new...
17
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late...
3
by: DK | last post by:
This particular area of the program builds a Excel spreadsheet for the user to manipulate further. After turning Option Strict On and correcting everything I can the following line remains -- any...
14
by: Siv | last post by:
hi, I am converting an application that writes to an Excel spreadsheet and the code trips the "option Strict" that I would like on because the parser says "option Strict On disallows late...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.