473,396 Members | 2,011 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,396 software developers and data experts.

Dynamically creating type of System.Int32, how??

Hi

How do I dynamically create a type of System.Int32 with the value 123?? I've tried the following:

Dim keyci As ConstructorInfo = Type.GetType("System.Int32").GetConstructor(New Type() {Type.GetType("System.Int32")})
Dim key As Object = keyci.Invoke(New Object() {"123"})
however it doesn't seem to work....

TIA

Søren

Nov 21 '05 #1
3 2047
"Søren M. Olesen" <sm******@hotmail.com> schrieb:
How do I dynamically create a type of System.Int32 with the value 123??
I've tried the following:

Dim keyci As ConstructorInfo =
Type.GetType("System.Int32").GetConstructor(New Type()
{Type.GetType("System.Int32")})
Dim key As Object = keyci.Invoke(New Object() {"123"})

however it doesn't seem to work....


.... because 'Int32' doesn't have a parameterized constructor.

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

Nov 21 '05 #2
I kind of figured that, but is there a way to do it, or do I have to use a
select case and then cast on the type??

Søren

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OM**************@tk2msftngp13.phx.gbl...
"Søren M. Olesen" <sm******@hotmail.com> schrieb:
How do I dynamically create a type of System.Int32 with the value 123??
I've tried the following:

Dim keyci As ConstructorInfo =
Type.GetType("System.Int32").GetConstructor(Ne w Type()
{Type.GetType("System.Int32")})
Dim key As Object = keyci.Invoke(New Object() {"123"})

however it doesn't seem to work....


... because 'Int32' doesn't have a parameterized constructor.

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

Nov 21 '05 #3
Søren,
It appears you simply want to convert a String to an arbitrary type.

Have you considered Convert.ChangeType?

Something like:

Dim key As Object = Convert.ChangeType("123",
Type.GetType("System.Int32"))

Where the GetType changes based on outside criteria.

However if you know you will always be using Int32, then a simply cast is
easier:

Either of the following:
key = CInt("123")
key = Convert.ToInt32("123")
Hope this helps
Jay

"Søren M. Olesen" <sm******@hotmail.com> wrote in message
news:OX**************@TK2MSFTNGP10.phx.gbl...
Hi

How do I dynamically create a type of System.Int32 with the value 123?? I've
tried the following:

Dim keyci As ConstructorInfo =
Type.GetType("System.Int32").GetConstructor(New Type()
{Type.GetType("System.Int32")})
Dim key As Object = keyci.Invoke(New Object() {"123"})
however it doesn't seem to work....

TIA

Søren
Nov 21 '05 #4

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

Similar topics

2
by: fplisa | last post by:
Hi- I have code that dynamically adds 1 to 10 textboxes to a form. The user is asked how many boxes he/she needs. Problem is, I can't get to the events of each box that is added EXCEPT for the...
0
by: Matt Warner | last post by:
Hi guys, A couple of people have already posted questions about similar issues but haven't had any response. Occasionally, sometimes after running the app for a few hours, it bombs out saying...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
2
by: Roby Eisenbraun Martins | last post by:
Hi, My name is Roby Eisenbraun Martins, I am a C++, VB and NET developer. I am working with a NET 2002 project right now and I am receiving this uncommon "OutOfMemory" error message when I try...
2
by: blue | last post by:
I have a class called "MyClass". At runtime, I don't know that the class is of type MyClass but I do know the string name of the class. Is there a way to create an instance of a class when I only...
0
by: Earl Teigrob | last post by:
I have created a Custom Control that accepts an array of Objects and uses the contents of those objects to add controls to its child control struture and have them rendered to the display. I also...
7
by: RSS | last post by:
Hi everyone, I have an app that uses some DLL's that are shared across couple applications. There are reasons existing that prevent me from putting them in to the GAC. Each of these app's at some...
1
by: Frank | last post by:
I have read and followed Scott Mitchells' tutorial, Creating a 'Business Logic Layer', @ http://www.asp.net/learn/dataaccess/tutorial02cs.aspx?tabid=63, and it occurred to me that he did not...
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi, thanks, mister The code string rutaConfig = tbRutaConfigServicioBase.Text; '// Map to the application configuration file. ExeConfigurationFileMap configFile = New...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.