Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Import Microsoft.VisualBasic for IsNumeric?

Reply
Thread Tools

Import Microsoft.VisualBasic for IsNumeric?

 
 
=?Utf-8?B?RGF2ZQ==?=
Guest
Posts: n/a
 
      01-16-2006
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      01-16-2006
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

 
Reply With Quote
 
 
 
 
Lau Lei Cheong
Guest
Posts: n/a
 
      01-16-2006
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" <(E-Mail Removed)> 级糶秎ン穝籇:(E-Mail Removed)...
> 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



 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      01-16-2006
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" <(E-Mail Removed)> 录露录g漏贸露l楼贸路s禄D:(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      01-16-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> 级糶秎ン穝籇:(E-Mail Removed)...
>> 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

>
>



 
Reply With Quote
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      01-16-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> 级糶秎ン穝籇:(E-Mail Removed)...
>> 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

>
>



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      01-16-2006
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)>
>> 级糶秎ン穝籇:(E-Mail Removed)...
>> > 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

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      01-16-2006
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" <(E-Mail Removed)> 录露录g漏贸露l楼贸路s禄D:(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
Lau Lei Cheong
Guest
Posts: n/a
 
      01-17-2006
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]" <(E-Mail Removed)> 级糶秎ン穝籇:(E-Mail Removed)...
> 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" <(E-Mail Removed)> ???gco?los?D:(E-Mail Removed)...
>>
>> > 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

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
to use import java.lang.* or import java.lang.Math or none at all? JPractitioner Java 13 02-24-2006 08:48 PM
XML Schema question - does "import" import elements? Vitali Gontsharuk XML 2 08-25-2005 07:33 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM
GTK import doesn't import first time Dennis Python 2 08-18-2003 10:00 PM
import/from import question Artur M. Piwko Python 1 07-02-2003 07:04 PM



Advertisments