473,671 Members | 2,341 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ctype

AXH
Hi All,

I have to following problem.
Is it possible type convert a stringvalue to a type value.
Please look below for the example
dim regvalue as string= "123456"
dim regtype as string = "String"

private function GetValue as object
return ctype(regvalue, ?????????)
end function

Thanks,
AXH
Aug 15 '06 #1
4 1918
AXH wrote:
Hi All,

I have to following problem.
Is it possible type convert a stringvalue to a type value.
Please look below for the example
dim regvalue as string= "123456"
dim regtype as string = "String"

private function GetValue as object
return ctype(regvalue, ?????????)
end function

Thanks,
AXH

I might not have this exact as I don't have my compiler here but it's
something like:

return ctype(regvalue, Type.GetType(re gtype))

of course in your example this won't do much since your function is
returning a type object.
Aug 15 '06 #2
AXH

"Chris" <no@spam.comwro te in message
news:eY******** *****@TK2MSFTNG P05.phx.gbl...
AXH wrote:
>Hi All,

I have to following problem.
Is it possible type convert a stringvalue to a type value.
Please look below for the example
dim regvalue as string= "123456"
dim regtype as string = "String"

private function GetValue as object
return ctype(regvalue, ?????????)
end function

Thanks,
AXH

I might not have this exact as I don't have my compiler here but it's
something like:

return ctype(regvalue, Type.GetType(re gtype))

of course in your example this won't do much since your function is
returning a type object.

The above code isn't working oke. I will het an error.

Anyone suggestions !!

Thanks
Aug 15 '06 #3
AXH,
It sounds like you want to use Convert.ChangeT ype.

| dim regvalue as string= "123456"
dim regtype as string = "System.Str ing"
|
| private function GetValue as object
Return Convert.ChangeT ype(regvalue, Type.GetType(re gtype))
| end function

NOTE: regtype needs to be one of the types listed in System.TypeCode ,
qualified with its namespace (such as System.String & System.Int32)

Alternatively you could simply use the overload that accepted
System.TypeCode or use GetType(String) & GetType(Integer )...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"AXH" <ax*******@hotm ail.comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
| Hi All,
|
| I have to following problem.
| Is it possible type convert a stringvalue to a type value.
| Please look below for the example
|
|
| dim regvalue as string= "123456"
| dim regtype as string = "String"
|
| private function GetValue as object
| return ctype(regvalue, ?????????)
| end function
|
| Thanks,
| AXH
|
|
Aug 15 '06 #4
AXH,

A string is a type.

You can set a string in an object
dim myObject as Object = CType("12345",O bject)

Althoug a little bit out of sence because
dim myObject as Object = "12345" works impliciet

I hope this helps,

Cor
"AXH" <ax*******@hotm ail.comschreef in bericht
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Hi All,

I have to following problem.
Is it possible type convert a stringvalue to a type value.
Please look below for the example
dim regvalue as string= "123456"
dim regtype as string = "String"

private function GetValue as object
return ctype(regvalue, ?????????)
end function

Thanks,
AXH

Aug 16 '06 #5

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

Similar topics

4
6560
by: Joeri | last post by:
Hi, I'm struggling with this issue, maybe someone has already solved ik before. Here's the problem I Have : clsA witch is a base class clsB inherits from clsA clsC inherits from clsA clsD inherits from clsA
1
1787
by: Logan X via .NET 247 | last post by:
It's official....Convert blows. I ran a number of tests converting a double to an integer usingboth Convert & CType. I *ASSUMED* that CType would piggy-back ontop of Convert, and that performance would be identical. I was 100% incorrect. The code below produces the results: CType Took: 0.2187528 seconds. Convert Took: 12.187656 seconds.
10
2325
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a similar name to the table. Rather than making a long Select Case that could become obsolete if lookup tables are added and the source table of the ListBox is edited I came up with this code.) This code works but of course it gives me build...
4
3831
by: Mike Cooper | last post by:
There is something about inherited classes I evidently don't know... I wrote the following class: Class Class1 inherits System.Windows.Forms.DataGridTextBoxColumn End Class There is absolutely no added functionality to it.
6
10826
by: Ot | last post by:
I apparently have a bit to learn about Casting and Conversion. I have been thinking of them as the same but a discussion in another thread leads me to believe that this is wrong thinking. I found this in the VB Language reference: <quote> The DirectCast keyword introduces a type conversion operation. You use it the same way you use the CType keyword.... Both keywords take an expression to be converted as the first argument, and
8
7352
by: John A Grandy | last post by:
could someone please discuss the pros and cons of CType(MyDouble,Decimal) versus Convert.ToDecimal(MyDouble) .... and other such conversions ...
16
298
by: Craig Buchanan | last post by:
If I am trying to cast an object to one of its decendants, will the decendants' default constructor (New sub) fire? Thanks, Craig
7
2712
by: Brian Henry | last post by:
is there any speed diffrences between doing Ctype or directcast? I know about the inherite diffrences, but process usage time wise, does one take up more cycles then the other? thanks
3
4562
by: Charles Law | last post by:
I have the following lines Dim t As Type = GetType(MyType) Dim serialiser As New XmlSerializer(t) I want to be able to do the following with a FileStream fs Dim instance As MyType instance = CType(serialiser.Deserialize(fs), MyType)
3
1790
by: Arpan | last post by:
The syntax of the function CType, as stated in the .NET 2 SDK Documentation, is CType(expression, typename) The Documentation also states that CType is compiled inline which means that the conversion code is part of the code that evaluates the expression.
0
8478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8919
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8821
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8599
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
8670
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5696
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
4225
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
4409
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2813
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

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.