473,699 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difficult one.. please help

Hi I have trying to solve this but I can't understand why it's not working.

I want to cast a variable dynamically with a type that I pass truogh a string.
I am receiving a value and want to check if the type is correct before saving it to the XML.
I am getting the Type from xsd and pass this to a function to convert the newvalue to the proper type.
I want to avoid doing if statement to check for the type and then try to convert it.

This is an example my code.

Dim strType as string = "System.Int 32"
Dim val as object

Dim type As Type = (type.GetType(s trType))

val = CType(val, Type)

I have tried also passing a different object of type 'Type'

Is this possible?

Please help

Nov 21 '05 #1
10 1037
Helllo mysterious,

Are you inventing the wheel, all is already build in.

Some examples
Dim a As Integer = 1
Dim b As String = "2"
Dim c As Decimal = 10.1D
Dim d As Integer
Dim f As Decimal
Dim g As String
Dim h As Object
d = CInt(b)
g = c.ToString
f = CDec(a)
h = a
d = CInt(h)

You need to cast it to the type you want and especially in that is VBNet
very powerfull. (I only showed you only a very small selection of methods to
do that)

Cor

I want to cast a variable dynamically with a type that I pass truogh a
string.
I am receiving a value and want to check if the type is correct before
saving it to the XML.
I am getting the Type from xsd and pass this to a function to convert the
newvalue to the proper type.
I want to avoid doing if statement to check for the type and then try to
convert it.

This is an example my code.

Dim strType as string = "System.Int 32"
Dim val as object
Dim type As Type = (type.GetType(s trType))
val = CType(val, Type)
I have tried also passing a different object of type 'Type'
Is this possible?

Please help
Nov 21 '05 #2
I think your missing his point. He wants to cast at runtime, and use the
typename in a string to determine what type the object will be cast to.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Helllo mysterious,

Are you inventing the wheel, all is already build in.

Some examples
Dim a As Integer = 1
Dim b As String = "2"
Dim c As Decimal = 10.1D
Dim d As Integer
Dim f As Decimal
Dim g As String
Dim h As Object
d = CInt(b)
g = c.ToString
f = CDec(a)
h = a
d = CInt(h)

You need to cast it to the type you want and especially in that is VBNet
very powerfull. (I only showed you only a very small selection of methods to do that)

Cor

I want to cast a variable dynamically with a type that I pass truogh a
string.
I am receiving a value and want to check if the type is correct before
saving it to the XML.
I am getting the Type from xsd and pass this to a function to convert the
newvalue to the proper type.
I want to avoid doing if statement to check for the type and then try to
convert it.

This is an example my code.

Dim strType as string = "System.Int 32"
Dim val as object
Dim type As Type = (type.GetType(s trType))
val = CType(val, Type)
I have tried also passing a different object of type 'Type'
Is this possible?

Please help

Nov 21 '05 #3
Terry,

I know however I wrote inventing the wheel, why would that be needed, one
reason can be that a lot of people are looking to use the Var from scripting
languages, however when you put a value in a object there is not any need
for that.

You can get it back by just naming the type of the receiving value.

Cor
Nov 21 '05 #4
In his scenario, he needs to discover the type for his XML storage.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:eU******** ******@tk2msftn gp13.phx.gbl...
Terry,

I know however I wrote inventing the wheel, why would that be needed, one
reason can be that a lot of people are looking to use the Var from scripting languages, however when you put a value in a object there is not any need
for that.

You can get it back by just naming the type of the receiving value.

Cor

Nov 21 '05 #5
Terry

As sender you can just cast it as I wrote, as a receiving field it is with
the informaiton I have now an almost a ridiculous question.

A kind of inventing the wheel.

I know that you can make a loop in it to fill it, however from where than?

Create an unknown XML file from an unknown table

(when it is a datatable by the way it is)
ds.add.table(x)

Cor
Nov 21 '05 #6
OK, when you create an XML/XSD combination, you need to know the Type of the
Data. He is saying he does not know this at design time, so he needs to
check this when he creates the XSD. I understand what you are saying, but
I'm not yet convinced that this is enough for the OP, he has not been
verbosely Explicit in what he is trying to achieve, so I think we should
wait until he replies rather than trying to interpolate his post.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:ei******** ******@TK2MSFTN GP10.phx.gbl...
Terry

As sender you can just cast it as I wrote, as a receiving field it is with
the informaiton I have now an almost a ridiculous question.

A kind of inventing the wheel.

I know that you can make a loop in it to fill it, however from where than?
Create an unknown XML file from an unknown table

(when it is a datatable by the way it is)
ds.add.table(x)

Cor

Nov 21 '05 #7
On 2004-08-27, <.> <> wrote:
This is a multi-part message in MIME format.

------=_NextPart_000_ 000A_01C48C4E.A 386BA70
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
If you could turn that off, it would be nice...

Hi I have trying to solve this but I can't understand why it's not =
working.


The problem is that CType doesn't do what you think it does. It isn't a
runtime function taking a System.Type, it's a keyword that is bound at
compile time.

Also, Type.GetType is really worth avoiding if possible, there's all
kinds of undocumented wackiness in there.

All in all, if it's possible your best bet is to follow Cor's advice.
Have some sort of dispatch function that includes all the types you care
about in a case statement, and hard-code the conversions...

Select Case typeString
Case "System.Int 32"
variable = CInt(s)

Case "System.Boolean "
variable = CBool(s)
And so on...

Nov 21 '05 #8
Hi There,

what I'm need to do is to validate the NewValue before saving it in the xml.
At the moment I am validating the xml/xsd everytime I change a value.

I would like to avoid writting the following
Select Case typeString
Case "System.Int 32"
variable = CInt(s)

Case "System.Boolean "
variable = CBool(s)

but for some reason I can't use the following
I am getting the Datatype from the XSD Schema file.
I hope I made myself clearer...

Thanks for the help and coments.

Example of what I am trying to achieve..

covertType ("xx", XMLSchemType)

private function convertType(byr ef val as string , byref strType as string)

' this is return from XMLSchemaType ---- "System.Int 32"
Dim newval as object

Dim myType As Type = (type.GetType(X MLSchemaType))

try
newval = CType(val, myType) ---- although myType is Type it will not be
accepted.. How can I do this..
Catch er as Exeption
console.write ("Value is of wrong data type")
End Try

end function

Nov 21 '05 #9
..
It sounds like you want to use Convert.ChangeT ype.

Dim strType as string = "System.Int 32"
Dim val as object

Dim type As Type = (type.GetType(s trType))

val = "100"

val = Convert.ChangeT ype(val, type)

Will convert the string "100" to the integer 100.

See System.Convert class for restrictions.

Hope this helps
Jay
<.> wrote in message news:un******** ******@TK2MSFTN GP11.phx.gbl...
Hi I have trying to solve this but I can't understand why it's not working.

I want to cast a variable dynamically with a type that I pass truogh a
string.
I am receiving a value and want to check if the type is correct before
saving it to the XML.
I am getting the Type from xsd and pass this to a function to convert the
newvalue to the proper type.
I want to avoid doing if statement to check for the type and then try to
convert it.

This is an example my code.

Dim strType as string = "System.Int 32"
Dim val as object

Dim type As Type = (type.GetType(s trType))

val = CType(val, Type)

I have tried also passing a different object of type 'Type'

Is this possible?

Please help
Nov 21 '05 #10

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

Similar topics

6
3732
by: PerryC | last post by:
I have search googles and there are hundreds of tips about AllowByPassKey... however, none works for me... well, perhaps I am too new to such high level functionality that it just does not make sense to me. So, anyone please help. I have no idea what is "CreateProperty" that Access help was trying to tell me to do. Can anyone please write me a step by step on how to accomplish this? (i.e. disable Shift on Startup.) I've seen many...
7
650
by: PerryC | last post by:
I have search googles and there are hundreds of tips about AllowByPassKey... however, none works for me... well, perhaps I am too new to such high level functionality that it just does not make sense to me. So, anyone please help. I have no idea what is "CreateProperty" that Access help was trying to tell me to do. Can anyone please write me a step by step on how to accomplish this? (i.e. disable Shift on Startup.) I've seen many...
8
2018
by: Senderos | last post by:
Hello, i try to break this code, since many days (and nights), without any success : <script type="text/javascript"> function p(a,i,c) { var x=a.charCodeAt(i)+c;
2
1874
by: holdingbe | last post by:
Hi, I get very difficult requirement from my friend. I explain clearly below : I have two databases. Source databases: Flower |__________schema: sample. |______table :emp,dept,bonus,qa
7
2055
by: WannabePrgmr | last post by:
What I am trying to do is on the click event of "Command167", run a Dlookup on the number that was just typed into "cboMoveTo1" and find the value located in the table "tblName" in the "Open/Closed" field. The Dlookup seems to work fine on its own. I tested it with a text box that was set to: = DLookup("", "", " = " & !!) and it would bring back the correct data. Then what I need it to do is check to see if the Dlookup return...
1
8916
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7752
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3058
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
2
2348
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2010
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.