By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,967 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,967 IT Pros & Developers. It's quick & easy.

Import Microsoft.VisualBasic for IsNumeric?

P: n/a
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function in
my C# code but all I see is:

Microsoft.VisualBasic.VBCodeProvider while using Intellisense...

From samples shouldn't I see Microsoft.VisualBasic.Information.IsNumeric?

Thanks
Jan 16 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Sounds like you imported the wrong assembly.

It's Microsoft.VisualBasic.dll that you want. This contains the .Information
namespace, which has the IsNumeric method.
I'm not even going to get into why it might be better not to do this, I'll
just get flamed.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Dave" wrote:
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function in
my C# code but all I see is:

Microsoft.VisualBasic.VBCodeProvider while using Intellisense...

From samples shouldn't I see Microsoft.VisualBasic.Information.IsNumeric?

Thanks

Jan 16 '06 #2

P: n/a
After you imported Microsoft.VisualBasic namespace, when you type
"IsNumeric(", does the Intellisense show up?

And I wish to ask another question. For the OP's purpose, he can use the
IsNumeric() function from Microsoft.VisualBasic namespace, or attempt to
write one for himself with the following:

public static bool InNumeric(string inputstr)
{
bool result = false;
try
{
decimal temp = Convert.ToDecimal(inputstr);
result = true;
}
catch
{
result = false;
}
return result;
}

Of course he may also determine the result by comparing the ASCII values of
the string one by one for "0"-"9" and "." (possibly "e" and so on if
applicable)

For the above methods, which one is recommended to do in C#?

"Dave" <Da**@discussions.microsoft.com> 级糶秎ン穝籇:5B********************************* *@microsoft.com...
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function
in
my C# code but all I see is:

Microsoft.VisualBasic.VBCodeProvider while using Intellisense...

From samples shouldn't I see Microsoft.VisualBasic.Information.IsNumeric?

Thanks

Jan 16 '06 #3

P: n/a
The IsNumeric method from Microsoft.VisualBasic is not that simple. It does
an incredible amount of complex type-checking with culture, Iconvertible,
etc. under the hood.

However, if you want a C# "Simplistic" version, I'd suggest using
double.TryParse, which does not throw an exception.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Lau Lei Cheong" wrote:
After you imported Microsoft.VisualBasic namespace, when you type
"IsNumeric(", does the Intellisense show up?

And I wish to ask another question. For the OP's purpose, he can use the
IsNumeric() function from Microsoft.VisualBasic namespace, or attempt to
write one for himself with the following:

public static bool InNumeric(string inputstr)
{
bool result = false;
try
{
decimal temp = Convert.ToDecimal(inputstr);
result = true;
}
catch
{
result = false;
}
return result;
}

Of course he may also determine the result by comparing the ASCII values of
the string one by one for "0"-"9" and "." (possibly "e" and so on if
applicable)

For the above methods, which one is recommended to do in C#?

"Dave" <Da**@discussions.microsoft.com> 录露录g漏贸露l楼贸路s禄D:5B*********************** ***********@microsoft.com...
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function
in
my C# code but all I see is:

Microsoft.VisualBasic.VBCodeProvider while using Intellisense...

From samples shouldn't I see Microsoft.VisualBasic.Information.IsNumeric?

Thanks


Jan 16 '06 #4

P: n/a
In .Net 2.0, you can take advantage of the TryParse() implementations for
various classes, without having to use Exception handling. Example:

puvlic static bool IsNumeric(string input)
{
double d;
return Double.TryParse(s, out d);
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:ew*************@TK2MSFTNGP15.phx.gbl...
After you imported Microsoft.VisualBasic namespace, when you type
"IsNumeric(", does the Intellisense show up?

And I wish to ask another question. For the OP's purpose, he can use the
IsNumeric() function from Microsoft.VisualBasic namespace, or attempt to
write one for himself with the following:

public static bool InNumeric(string inputstr)
{
bool result = false;
try
{
decimal temp = Convert.ToDecimal(inputstr);
result = true;
}
catch
{
result = false;
}
return result;
}

Of course he may also determine the result by comparing the ASCII values
of the string one by one for "0"-"9" and "." (possibly "e" and so on if
applicable)

For the above methods, which one is recommended to do in C#?

"Dave" <Da**@discussions.microsoft.com>
级糶秎ン穝籇:5B********************************* *@microsoft.com...
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function
in
my C# code but all I see is:

Microsoft.VisualBasic.VBCodeProvider while using Intellisense...

From samples shouldn't I see Microsoft.VisualBasic.Information.IsNumeric?

Thanks


Jan 16 '06 #5

P: n/a
The code swallows exceptions unecessarily.

if (value == null || value == DBNull.Value)
{
return false;
}
try
{
Decimal.Parse(value.ToString());
return true;
}
catch (Exception ex)
{
if ((ex is FormatException) || (ex is InvalidCastException) || (ex is
OverflowException))
{
return false;
}
throw;
}
Karl

--
http://www.openmymind.net/

"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:ew*************@TK2MSFTNGP15.phx.gbl...
After you imported Microsoft.VisualBasic namespace, when you type
"IsNumeric(", does the Intellisense show up?

And I wish to ask another question. For the OP's purpose, he can use the
IsNumeric() function from Microsoft.VisualBasic namespace, or attempt to
write one for himself with the following:

public static bool InNumeric(string inputstr)
{
bool result = false;
try
{
decimal temp = Convert.ToDecimal(inputstr);
result = true;
}
catch
{
result = false;
}
return result;
}

Of course he may also determine the result by comparing the ASCII values
of the string one by one for "0"-"9" and "." (possibly "e" and so on if
applicable)

For the above methods, which one is recommended to do in C#?

"Dave" <Da**@discussions.microsoft.com>
级糶秎ン穝籇:5B********************************* *@microsoft.com...
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function
in
my C# code but all I see is:

Microsoft.VisualBasic.VBCodeProvider while using Intellisense...

From samples shouldn't I see Microsoft.VisualBasic.Information.IsNumeric?

Thanks


Jan 16 '06 #6

P: n/a
Actually, there is an overload of TryParse that can be used to do the same
type-checking and so on. I didn't post it for simplicity's sake, but it's
good to mention it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:F1**********************************@microsof t.com...
The IsNumeric method from Microsoft.VisualBasic is not that simple. It
does
an incredible amount of complex type-checking with culture, Iconvertible,
etc. under the hood.

However, if you want a C# "Simplistic" version, I'd suggest using
double.TryParse, which does not throw an exception.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Lau Lei Cheong" wrote:
After you imported Microsoft.VisualBasic namespace, when you type
"IsNumeric(", does the Intellisense show up?

And I wish to ask another question. For the OP's purpose, he can use the
IsNumeric() function from Microsoft.VisualBasic namespace, or attempt to
write one for himself with the following:

public static bool InNumeric(string inputstr)
{
bool result = false;
try
{
decimal temp = Convert.ToDecimal(inputstr);
result = true;
}
catch
{
result = false;
}
return result;
}

Of course he may also determine the result by comparing the ASCII values
of
the string one by one for "0"-"9" and "." (possibly "e" and so on if
applicable)

For the above methods, which one is recommended to do in C#?

"Dave" <Da**@discussions.microsoft.com>
级糶秎ン穝籇:5B********************************* *@microsoft.com...
> I'm trying to import Microsoft.VisualBasic to use the IsNumeric
> function
> in
> my C# code but all I see is:
>
> Microsoft.VisualBasic.VBCodeProvider while using Intellisense...
>
> From samples shouldn't I see
> Microsoft.VisualBasic.Information.IsNumeric?
>
> Thanks


Jan 16 '06 #7

P: n/a
You should never code around exception handling into your core logic.
Exception handling should be handling true exceptions, not the things you
expect. (It's also very inefficient to handle exceptions within your core
logic).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

"Lau Lei Cheong" wrote:
After you imported Microsoft.VisualBasic namespace, when you type
"IsNumeric(", does the Intellisense show up?

And I wish to ask another question. For the OP's purpose, he can use the
IsNumeric() function from Microsoft.VisualBasic namespace, or attempt to
write one for himself with the following:

public static bool InNumeric(string inputstr)
{
bool result = false;
try
{
decimal temp = Convert.ToDecimal(inputstr);
result = true;
}
catch
{
result = false;
}
return result;
}

Of course he may also determine the result by comparing the ASCII values of
the string one by one for "0"-"9" and "." (possibly "e" and so on if
applicable)

For the above methods, which one is recommended to do in C#?

"Dave" <Da**@discussions.microsoft.com> 录露录g漏贸露l楼贸路s禄D:5B*********************** ***********@microsoft.com...
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function
in
my C# code but all I see is:

Microsoft.VisualBasic.VBCodeProvider while using Intellisense...

From samples shouldn't I see Microsoft.VisualBasic.Information.IsNumeric?

Thanks


Jan 16 '06 #8

P: n/a
I see.

But... for the purpose of assignment to a variable, I think checking to see
if it can be successfully assigned to a variable of that variable type is
good enough. Isn't it?

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> 级糶秎ン穝籇:F1********************************* *@microsoft.com...
The IsNumeric method from Microsoft.VisualBasic is not that simple. It
does
an incredible amount of complex type-checking with culture, Iconvertible,
etc. under the hood.

However, if you want a C# "Simplistic" version, I'd suggest using
double.TryParse, which does not throw an exception.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Lau Lei Cheong" wrote:
After you imported Microsoft.VisualBasic namespace, when you type
"IsNumeric(", does the Intellisense show up?

And I wish to ask another question. For the OP's purpose, he can use the
IsNumeric() function from Microsoft.VisualBasic namespace, or attempt to
write one for himself with the following:

public static bool InNumeric(string inputstr)
{
bool result = false;
try
{
decimal temp = Convert.ToDecimal(inputstr);
result = true;
}
catch
{
result = false;
}
return result;
}

Of course he may also determine the result by comparing the ASCII values
of
the string one by one for "0"-"9" and "." (possibly "e" and so on if
applicable)

For the above methods, which one is recommended to do in C#?

"Dave" <Da**@discussions.microsoft.com> ???gco?los?D:5B******************************* ***@microsoft.com...
> I'm trying to import Microsoft.VisualBasic to use the IsNumeric
> function
> in
> my C# code but all I see is:
>
> Microsoft.VisualBasic.VBCodeProvider while using Intellisense...
>
> From samples shouldn't I see
> Microsoft.VisualBasic.Information.IsNumeric?
>
> Thanks


Jan 17 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.