473,569 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("S ystem.Int32").G etConstructor(N ew Type() {Type.GetType(" System.Int32")} )
Dim key As Object = keyci.Invoke(Ne w Object() {"123"})
however it doesn't seem to work....

TIA

Søren

Nov 21 '05 #1
3 2055
"Søren M. Olesen" <sm******@hotma il.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(Ne w 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******** ******@tk2msftn gp13.phx.gbl...
"Søren M. Olesen" <sm******@hotma il.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(Ne w 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.ChangeT ype?

Something like:

Dim key As Object = Convert.ChangeT ype("123",
Type.GetType("S ystem.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******@hotma il.com> wrote in message
news:OX******** ******@TK2MSFTN GP10.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("S ystem.Int32").G etConstructor(N ew Type()
{Type.GetType(" System.Int32")} )
Dim key As Object = keyci.Invoke(Ne w 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
355
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 last one. I need to do a running total of the text boxes as the user enters a value and moves onto the next textbox
0
600
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 that it could not create a windows handle. On one machine the stacktrace is this:
6
3235
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." exception. The problem is that this exception isn't raised somewhere in a method, so it just shows up, and it causes the application to shut down. ...
2
2390
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 to load a form object ( new frmMain() ). In debug mode, the "Load" form method is executed but it crashes when it tries to set a DataTable from a...
2
8797
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 know it's name? I was looking at: Type myType1 = Type.GetType("System.Int32"); myType1 = 10; // error because myType is of type Type, not...
0
1652
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 add this array of objects to view state and regenerate the objects on postback using the System.Activator.CreateInstance Method. This all seems to...
7
1725
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 point in time loads a DLL dynamically in this fashion: System.Reflection.Assembly assembly = null; assembly =...
1
6927
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 include the InsertProduct("New Product", 1, 1, "12 tins per carton", 14.95m, 10, 0, 10, false) function in the BLL. Prior to implementing the BLL, in...
0
2611
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 ExeConfigurationFileMap();
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7666
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.