472,992 Members | 3,075 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to convert a string variable dynamic to another type?

I have problems with this Code:

Public Sub SetPropertyValue(ByVal strPropertyPath As String, ByVal obj
As Object, ByVal Value As Object)
.....
Dim t_PropertyInfos() As System.Reflection.PropertyInfo =
(t_obj.GetType).GetProperties
For ii = 0 To t_PropertyInfos.Length - 1
If t_PropertyInfos(ii).Name = t_strProperty Then
t_PropertyInfos(ii).SetValue(t_obj, Value, Nothing)
End If
Next

I get the following error message:
An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll
Additional information: Zieltyp kann nicht zu primitiven Typ erweitert
werden.

"t_PropertyInfos(ii)" required a Double und the "Value" is a String,
for example "10".

I can get the Type of my Property with:
Dim t_type As Type = t_PropertyInfos(ii).PropertyType

But how can i convert my Value in this type?

I tryed:
Value = CType(Value, t_type)
and alsoe
Value = DirectCast(Value, t_type)

There are both a Syntax Error:
"Type 't_type' is not defined.

Is there any method to convert a variable to a dynamicl type?

Jun 23 '06 #1
4 2830
Dim MyDouble As Double = Double.Parse(MyString);
<a.*******@gmx.ch> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
I have problems with this Code:

Public Sub SetPropertyValue(ByVal strPropertyPath As String, ByVal obj
As Object, ByVal Value As Object)
....
Dim t_PropertyInfos() As System.Reflection.PropertyInfo =
(t_obj.GetType).GetProperties
For ii = 0 To t_PropertyInfos.Length - 1
If t_PropertyInfos(ii).Name = t_strProperty Then
t_PropertyInfos(ii).SetValue(t_obj, Value, Nothing)
End If
Next

I get the following error message:
An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll
Additional information: Zieltyp kann nicht zu primitiven Typ erweitert
werden.

"t_PropertyInfos(ii)" required a Double und the "Value" is a String,
for example "10".

I can get the Type of my Property with:
Dim t_type As Type = t_PropertyInfos(ii).PropertyType

But how can i convert my Value in this type?

I tryed:
Value = CType(Value, t_type)
and alsoe
Value = DirectCast(Value, t_type)

There are both a Syntax Error:
"Type 't_type' is not defined.

Is there any method to convert a variable to a dynamicl type?

Jun 23 '06 #2
I'm not sure, but have you tried the following?

CType(Value, t_obj.GetType)
or maybe
CType(Value, GetType(t_obj))

Hope this helps,

Joris


"a.*******@gmx.ch" wrote:
I have problems with this Code:

Public Sub SetPropertyValue(ByVal strPropertyPath As String, ByVal obj
As Object, ByVal Value As Object)
.....
Dim t_PropertyInfos() As System.Reflection.PropertyInfo =
(t_obj.GetType).GetProperties
For ii = 0 To t_PropertyInfos.Length - 1
If t_PropertyInfos(ii).Name = t_strProperty Then
t_PropertyInfos(ii).SetValue(t_obj, Value, Nothing)
End If
Next

I get the following error message:
An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll
Additional information: Zieltyp kann nicht zu primitiven Typ erweitert
werden.

"t_PropertyInfos(ii)" required a Double und the "Value" is a String,
for example "10".

I can get the Type of my Property with:
Dim t_type As Type = t_PropertyInfos(ii).PropertyType

But how can i convert my Value in this type?

I tryed:
Value = CType(Value, t_type)
and alsoe
Value = DirectCast(Value, t_type)

There are both a Syntax Error:
"Type 't_type' is not defined.

Is there any method to convert a variable to a dynamicl type?

Jun 23 '06 #3
This would be go when "t_PropertyInfos(ii)" required allways a Double,
but in the "t_PropertyInfos(ii+1) requires perhaps a Int. So I don't
know at Design-Time which type my property need.
Stuart Irving schrieb:
Dim MyDouble As Double = Double.Parse(MyString);


Jun 26 '06 #4
There are also both a Syntax Error

Joris Zwaenepoel schrieb:
I'm not sure, but have you tried the following?

CType(Value, t_obj.GetType)
or maybe
CType(Value, GetType(t_obj))

Hope this helps,

Joris


Jun 26 '06 #5

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

Similar topics

134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
7
by: Jim Bancroft | last post by:
Hi everyone, A basic one here, I think. I haven't found the pattern yet, but sometimes when I cast a variable to another type using the "C" style cast operator the compiler refuses to play...
2
by: Martin | last post by:
I would like to convert this code to VB.NET. Can someone help. Thanks. Dim X() Dim i As Long Dim objShell, objFolder, objFolderItem Dim FSO, oFolder, Fil Sub MainExtractData()
5
by: Allerdyce.John | last post by:
Do I need to convert string to integer in python? or it will do it for me (since dynamic type)? In my python script, I have this line: x /= 10; when i run it, I get this error: TypeError:...
8
by: Polaris431 | last post by:
I have a buffer that holds characters. Four characters in a row represent an unsigned 32 bit value. I want to convert these characters to a 32 bit value. For example: char buffer; buffer =...
7
by: Saber | last post by:
In an ASP.Net Website I've a string and want to convert that to Type. Let's consider the string "Class1" I tried: Type t = Type.GetType("Class1"); but it returns null.
2
by: yinglcs | last post by:
Can you please tell me why the following code does not work in python? My guess is I need to convert 'count' from a string to an integer. How can I do that? And my understanding is python is a...
3
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; ...
0
by: tickle | last post by:
Need to convert this PL/SQL script to Dynamic SQL Method 2 * copybook - celg02u3.sql SIR 24265 * * updates dt_deny for all rows in * * ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.