How can I convert a string to a different type based on another string or
other variable?
For instance, instead of
Dim i as Integer
i = ctype("1000", Integer)
I would like to do
Dim i as Integer
i = ctype("1000","Integer")
In other words the type conversion would be done programmatically, rather
than specified in the code.
In old VB the 'types' had values (like Integer =3, Long = 4, etc). Is there
something similar in .NET?
TIA
--
Alphonse Giambrone
Email: a-giam at customdatasolutions dot us 7 1683
use a switch() statement and ctype() accordingly
--
Curt Christianson
Owner/Lead Developer, DF-Software www.Darkfalz.com
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message
news:u%****************@TK2MSFTNGP11.phx.gbl... How can I convert a string to a different type based on another string or other variable?
For instance, instead of Dim i as Integer
i = ctype("1000", Integer)
I would like to do
Dim i as Integer
i = ctype("1000","Integer")
In other words the type conversion would be done programmatically, rather than specified in the code.
In old VB the 'types' had values (like Integer =3, Long = 4, etc). Is
there something similar in .NET?
TIA --
Alphonse Giambrone Email: a-giam at customdatasolutions dot us
Alphonse,
You could do this:
Dim i As Integer = CType("1000", System.Type.GetType("System.Int32"))
Where:
System.Type.GetType([Type Name As String])
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
Free code library at: www.aboutfortunate.com
"Out of chaos comes order."
Nietzche
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message
news:u%****************@TK2MSFTNGP11.phx.gbl... How can I convert a string to a different type based on another string or other variable?
For instance, instead of Dim i as Integer
i = ctype("1000", Integer)
I would like to do
Dim i as Integer
i = ctype("1000","Integer")
In other words the type conversion would be done programmatically, rather than specified in the code.
In old VB the 'types' had values (like Integer =3, Long = 4, etc). Is
there something similar in .NET?
TIA --
Alphonse Giambrone Email: a-giam at customdatasolutions dot us
Your question doesn't make sense as stated. What exactly are you trying to
accomplish? What is your requirement?
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message
news:u#**************@TK2MSFTNGP11.phx.gbl... How can I convert a string to a different type based on another string or other variable?
For instance, instead of Dim i as Integer
i = ctype("1000", Integer)
I would like to do
Dim i as Integer
i = ctype("1000","Integer")
In other words the type conversion would be done programmatically, rather than specified in the code.
In old VB the 'types' had values (like Integer =3, Long = 4, etc). Is
there something similar in .NET?
TIA --
Alphonse Giambrone Email: a-giam at customdatasolutions dot us
Thanks, that would work, but I thought there should be a more compact way.
It is really not a necessity, just that I feel I am missing something.
--
Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... use a switch() statement and ctype() accordingly
-- Curt Christianson Owner/Lead Developer, DF-Software www.Darkfalz.com
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message news:u%****************@TK2MSFTNGP11.phx.gbl... How can I convert a string to a different type based on another string
or other variable?
For instance, instead of Dim i as Integer
i = ctype("1000", Integer)
I would like to do
Dim i as Integer
i = ctype("1000","Integer")
In other words the type conversion would be done programmatically,
rather than specified in the code.
In old VB the 'types' had values (like Integer =3, Long = 4, etc). Is there something similar in .NET?
TIA --
Alphonse Giambrone Email: a-giam at customdatasolutions dot us
Thanks Justin,
That is the type of statement I am looking for, but it does not work.
Error is, System.Type.GetType is undefined.
--
Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:ud**************@tk2msftngp13.phx.gbl... Alphonse,
You could do this:
Dim i As Integer = CType("1000", System.Type.GetType("System.Int32"))
Where: System.Type.GetType([Type Name As String])
-- Sincerely,
S. Justin Gengo, MCP Web Developer / Programmer
Free code library at: www.aboutfortunate.com
"Out of chaos comes order." Nietzche
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message news:u%****************@TK2MSFTNGP11.phx.gbl... How can I convert a string to a different type based on another string
or other variable?
For instance, instead of Dim i as Integer
i = ctype("1000", Integer)
I would like to do
Dim i as Integer
i = ctype("1000","Integer")
In other words the type conversion would be done programmatically,
rather than specified in the code.
In old VB the 'types' had values (like Integer =3, Long = 4, etc). Is there something similar in .NET?
TIA --
Alphonse Giambrone Email: a-giam at customdatasolutions dot us
Sorry for the confusion, Kevin.
I know there are other ways to do this, but it is bugging me now.
Simplistically, I want to have a database table with 3 fields.
ItemField (text)
ValueField (text)
TypeField (could be integer, text or whatever is necessary)
ItemField would contain the description of a value to lookup (for example
"LastDatabaseCompact").
ValueField would contain the associated value as a string (for example
"1/4/2004").
TypeField would indicate the type of data in ValueField.
I would then have a function that could look up the value in ValueField for
the requested ItemField and return the result as the appropriate type. In
this example a date.
Skipping all the db connectivity, etc.
It would be something like
Return Ctype(ValueField, TypeField) '(this obviously would not work as
is).
--
Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:eS**************@TK2MSFTNGP09.phx.gbl... Your question doesn't make sense as stated. What exactly are you trying to accomplish? What is your requirement?
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Big things are made up of lots of little things.
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message news:u#**************@TK2MSFTNGP11.phx.gbl... How can I convert a string to a different type based on another string
or other variable?
For instance, instead of Dim i as Integer
i = ctype("1000", Integer)
I would like to do
Dim i as Integer
i = ctype("1000","Integer")
In other words the type conversion would be done programmatically,
rather than specified in the code.
In old VB the 'types' had values (like Integer =3, Long = 4, etc). Is there something similar in .NET?
TIA --
Alphonse Giambrone Email: a-giam at customdatasolutions dot us
Hi Alphonse,
You are getting an object is undefined error because CType does not allow
variables or calculations within the type parameter. The Visual Basic
Language Reference - CType Function documentation shows this:
typename
Any expression that is legal within an As clause in a Dim statement, that
is, the name of any data type, object, structure, class, or interface.
We are not allowed to dim a variable as type System.Type.GetType(...). The
same thing applies to the type parameter of the CType function.
I think you need to use a Select Case statement, as mentioned earlier.
Thank you, Mike
Microsoft, ASP.NET Support Professional
Microsoft highly recommends to all of our customers that they visit the http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computers security.
This posting is provided "AS IS", with no warranties, and confers no rights.
-------------------- Reply-To: "Alphonse Giambrone" <NO**********@example.invalid> From: "Alphonse Giambrone" <NO**********@example.invalid> References: <u#**************@TK2MSFTNGP11.phx.gbl>
<ud**************@tk2msftngp13.phx.gbl> Subject: Re: Type Conversion Date: Mon, 5 Jan 2004 16:00:14 -0500 Lines: 72 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: <eJ**************@TK2MSFTNGP11.phx.gbl> Newsgroups: microsoft.public.dotnet.framework.aspnet NNTP-Posting-Host: ool-4352027f.dyn.optonline.net 67.82.2.127 Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftng xa09.phx.gbl!TK2MSFTNGP08.
phx.gbl!TK2MSFTNGP11.phx.gbl Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:199830 X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
Thanks Justin,
That is the type of statement I am looking for, but it does not work. Error is, System.Type.GetType is undefined.
--
Alphonse Giambrone Email: a-giam at customdatasolutions dot us
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message news:ud**************@tk2msftngp13.phx.gbl... Alphonse,
You could do this:
Dim i As Integer = CType("1000", System.Type.GetType("System.Int32"))
Where: System.Type.GetType([Type Name As String])
-- Sincerely,
S. Justin Gengo, MCP Web Developer / Programmer
Free code library at: www.aboutfortunate.com
"Out of chaos comes order." Nietzche
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message news:u%****************@TK2MSFTNGP11.phx.gbl... How can I convert a string to a different type based on another string or other variable?
For instance, instead of Dim i as Integer
i = ctype("1000", Integer)
I would like to do
Dim i as Integer
i = ctype("1000","Integer")
In other words the type conversion would be done programmatically, rather than specified in the code.
In old VB the 'types' had values (like Integer =3, Long = 4, etc). Is there something similar in .NET?
TIA --
Alphonse Giambrone Email: a-giam at customdatasolutions dot us
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark Oliver |
last post by:
Hi, I want to put a type conversion in my class, but I don't want the
conversion to be usable in a passed parameter because it makes no sense.
class cData
{
string s;
public cData(string s)...
|
by: Madhu Gopinathan |
last post by:
Hi,
I hope this is the right forum for this question.
I am extending ICollection to create a Collection Type (say
MyCollection) wherein I can control the types of objects being added to the...
|
by: Yuriy Solodkyy |
last post by:
Hi
VS 2005 beta 2 successfully compiles the following:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1 {
class Program {
|
by: pgconnolly |
last post by:
/* foreach does implicit type conversion on elements of a params argument or
Generic.List.
* This is not good.
* Examples of evil follow...
*/
using System;
// I love it when C# is strict...
|
by: Enekajmer |
last post by:
Hi,
1 int main()
2 {
3 float a = 17.5;
4 printf("%d\n", a);
5 printf("%d\n", *(int *)&a);
6 return 0;
7 }
|
by: Martin v. Lwis |
last post by:
I've been working on PEP 353 for some time now.
Please comment, in particular if you are using 64-bit
systems.
Regards,
Martin
PEP: 353
Title: Using ssize_t as the index type
Version:...
|
by: lovecreatesbeauty |
last post by:
There is a warning/(error? I remember it is an error for line 10 on
some compilers before. At least on g++, it is an error.) for line 10. I
first read a similar example from `Expert C Programming...
|
by: Xah Lee |
last post by:
in March, i posted a essay “What is Expressiveness in a Computer
Language”, archived at:
http://xahlee.org/perl-python/what_is_expresiveness.html
I was informed then that there is a academic...
|
by: zaeminkr |
last post by:
I got a good answer here I have still confusing part.
I have two very simple classes
class DRect
{
private :
double x0, y0, x1, y1;
public :
DRect(double a, double b, double c, double d) :...
|
by: Smithers |
last post by:
Are there any important differences between the following two ways to
convert to a type?... where 'important differences' means something more
profound than a simple syntax preference of the...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shllpp 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |