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 8 3203
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
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
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
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> ¼¶¼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
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> ¼¶¼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
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> ¼¶¼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
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
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> ¼¶¼g©ó¶l¥ó·s»D: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¢Do¡Ps?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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Phil Powell |
last post by:
'GET THE HTML CONTENT FOR DISPLAY BAND ORIGIN
Dim bandOriginDropdown
On Error Resume Next
set scraper = Server.CreateObject("Microsoft.XMLHTTP")
if err then
bandOriginDropdown = ""
else...
|
by: Phil Latio |
last post by:
We have despatch process which kicks out picking information into text
files at hourly intervals.
The text files are named sequentially by process; 'ABC.txt',
'ABC01.txt', 'ABC02.txt' for one...
|
by: darrel |
last post by:
I've built a control. At the top of my control, I have this:
Imports Microsoft.VisualBasic
Then, later, I call a function like this:
DateTime.Now.Year.ToString()
This works fine on my...
|
by: Lance |
last post by:
Is there any way to create an import alias that applies
to the entire project? For example, lets say that I
want "VB" to represent Microsoft.VisualBasic throughout
my entire project. Is there...
|
by: frostalicious |
last post by:
Used VB.NET (on my client PC) to convert VB6 executable
to .NET executable. Placed the .exe file on a network drive
on my server. From client, ran .NET Wizards "Trust an
Assembly" to make the...
|
by: Steve |
last post by:
Having only recently migrated across from VB6 to VB.NET I'm still
unsure whether or not I should be making (heavy) use of the
Microsoft.VisualBasic namespace in new applications. I've read a lot...
|
by: Alexander Baranovsky |
last post by:
Hello friends,
How I can determine full path of Microsoft.Basic.dll?
Thanks,
Alexander
|
by: Rainer Queck |
last post by:
Hello NG,
are there any limitations to be considered, if I make use of objects in the
Microsoft.VisualBasic namespace?
Regards
Rainer Queck
|
by: TG |
last post by:
Hi!
I am trying to export only the visible columns from a datagridview in
my windows form in VB 2008.
Should't it be no comma after the first row where the headers are?
Also should...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
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: 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: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
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: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |