Exploring IsNumeric for C#

Posted 2003-03-11 08:22 AM in Web Services.

Some bits of code:.
C# version of IsNumeric( ) :
public static bool IsNumeric(object value){
   try    {
      int i = Convert.ToInt32(value.ToString());
      return true;
   }
      catch (FormatException)    {
      return false;
   }
}
[via The Wagner Blog]

Actually, this doesn't really do what IsNumeric does, as IsNumeric should also return true for floating point numbers.  This is really more of an "IsInt".
 
Also, why write your own?  You can just reference Microsoft.VisualBasic.dll, then do the following:
if (Microsoft.VisualBasic.Information.IsNumeric("5"))
{
 
//Do Something
}
The VB one actually performs better, as it doesn't throw an exception for every failed conversion.
[Sean 'Early' Campbell & Scott 'Adopter' Swigart's Radio Weblog]

What's REALLY interesting is what's going on in the Source Code (disassembled) for the VisualBasic.Information.IsNumeric (as I am trepidacious to include this dependancy (dunno why) in my code). 

Looks like it's pretty much the checking the Type of the object via iConvertable or the alternate TryParse...:

public static bool Isumeric (object Expression)
{
bool f;
ufloat64 a;
long l;

IConvertible iConvertible = null;
if ( ((Expression is IConvertible)))
{
   iConvertible = (IConvertible) Expression;
}

if (iConvertible == null)
{
   if ( ((Expression is char[])))
   {
       Expression = new String ((char[]) Expression);
       goto IL_002d; 'hopefully inserted by optimizer
   }
   return 0;
}
IL_002d:
TypeCode typeCode = iConvertible.GetTypeCode ();
if ((typeCode == 18) || (typeCode == 4))
{
    string str = iConvertible.ToString (null);
   try
   {
        if ( (StringType.IsHexOrOctValue (str, l)))
   {
        f = true;
        return f;
   }
}
catch (Exception )
{
    f = false;
    return f;
};
return DoubleType.TryParse (str, a);
}
return Utils.IsNumericTypeCode (typeCode);
}

internal static bool IsNumericType (Type typ)
{
bool f;
TypeCode typeCode;
if ( (typ.IsArray))
{
    return 0;
}
switch (Type.GetTypeCode (typ))
{
case 3:
case 6:
case 7:
case 9:
case 11:
case 13:
case 14:
case 15:
   return 1;
};
return 0;
}



The New Lifescan OneTouch UltraSmart

Posted 2003-03-11 05:17 AM in Diabetes | Reviews | Movies.

It came out and I ran to Fred Meyer to pick one up for myself.  I'm talking about the new Blood Glucose Meter from Lifescan, the OneTouch UltraSmart.  (Diabetics who are also geeks MUST have all the new toys)

If you wanted a review, here it is: The UltraSmart is the BEST meter I've ever used.  Full Stop.  I love it.

If you want more, read on.  It combines everything that is good about the original One Touch Ultra with a very complete logbook.  Also, thank goodness, it finally includes a backlight.  I can't tell you how many times I've needed to check my blood sugar in the movies and have struggled with the non-backlit Ultra.

Here's all you need to know:

  • Uses the same Ultra test strips you use now
  • Results in 5 seconds
  • Huge temperature range
  • Blue "Indiglo" Backlight
  • Graphs and trending data
  • Logging of Exercise, Carbos, Hypos, etc
  • Connects to OneTouch Software



The New Look for DiabeticBooks.com

Posted 2003-03-11 05:12 AM in Diabetes | XML.

In a rit of fealous jage and the inspiration of XML and CSS I updated my Diabetes Superstore http://www.diabeticbooks.com.  It's got a sexy new look and is dynamically updated by XML and XSLT taking the latest Amazon.com data and adding my review and comments of the latest books and information on Diabetes.  I've added new categories, I'm adding new books all the time.  If there's any desire for an RSS feed, let me know.  Enjoy!



Chris Brooks, my CTO, and I finally sat down to spend what we thought would be some serious time with Microsoft Office 2003's InfoPath and Chris Anderson's BlogX (Chris and some managers run BlogX internal blogs). 

We started up InfoPath, selected "New from Data Source" and pointed it at Chris's Internal Blog's WSDL.  We hooked up the CreateEntry Document to the CreateEntry Operation, and were presented with the Design View.  Rather than dragging one simple element at a time, we guessed and drug the whole CreateEntry and *poof* the form was sitting there.  We stared...exchanged "Oh, that was sweet" and continued.  We added name and password, a submit button and saved. 

We started up the Data Entry view, filled out the form, and nothing bad happened.  Suspicious thoughts filled the air, but we supressed them and visited Chris's blog...and dammit if the thing wasn't updated with our new entry.

As we sat and stared, I thought about the stacks of protocol layers and specificiations that we sat atop.  The false starts, the iterations, the consortiums, the presentations.  I thought of the day I first installed Trumpet Winsock on my Windows 3.1 machine and telneted to cdconnection.com, content to send my credit card number screaming in plaintext across the open Internet. 

The view from here is lovely.  I look forward to the things I can build with the things that have been built for me.



http://msdn.microsoft.com/events/pdc/

Microsoft Professional Developers Conference (PDC) 2003

October 27-31, 2003
Los Angeles, CA




Contact

Sponsors

Hosting By

Hot Topics

Tags

Calendar

<March 2003>
SunMonTueWedThuFriSat
2324252627281
2345678
9101112131415
16171819202122
23242526272829
303112345

Archives

February, 2010 (8)
January, 2010 (13)
December, 2009 (13)
November, 2009 (7)
October, 2009 (19)
September, 2009 (11)
August, 2009 (12)
July, 2009 (21)
June, 2009 (26)
May, 2009 (16)
April, 2009 (13)
March, 2009 (17)
February, 2009 (17)
January, 2009 (18)
December, 2008 (32)
November, 2008 (17)
October, 2008 (22)
September, 2008 (16)
August, 2008 (14)
July, 2008 (25)
June, 2008 (19)
May, 2008 (17)
April, 2008 (17)
March, 2008 (26)
February, 2008 (21)
January, 2008 (28)
December, 2007 (19)
November, 2007 (17)
October, 2007 (31)
September, 2007 (39)
August, 2007 (37)
July, 2007 (43)
June, 2007 (37)
May, 2007 (32)
April, 2007 (38)
March, 2007 (29)
February, 2007 (46)
January, 2007 (31)
December, 2006 (27)
November, 2006 (31)
October, 2006 (32)
September, 2006 (39)
August, 2006 (34)
July, 2006 (40)
June, 2006 (18)
May, 2006 (31)
April, 2006 (34)
March, 2006 (30)
February, 2006 (38)
January, 2006 (44)
December, 2005 (19)
November, 2005 (34)
October, 2005 (24)
September, 2005 (37)
August, 2005 (20)
July, 2005 (24)
June, 2005 (33)
May, 2005 (16)
April, 2005 (22)
March, 2005 (34)
February, 2005 (15)
January, 2005 (37)
December, 2004 (28)
November, 2004 (30)
October, 2004 (34)
September, 2004 (22)
August, 2004 (34)
July, 2004 (18)
June, 2004 (64)
May, 2004 (49)
April, 2004 (21)
March, 2004 (29)
February, 2004 (29)
January, 2004 (36)
December, 2003 (25)
November, 2003 (24)
October, 2003 (59)
September, 2003 (42)
August, 2003 (24)
July, 2003 (44)
June, 2003 (29)
May, 2003 (21)
April, 2003 (30)
March, 2003 (27)
February, 2003 (47)
January, 2003 (50)
December, 2002 (31)
November, 2002 (38)
October, 2002 (44)
September, 2002 (15)
May, 2002 (2)
April, 2002 (4)

Google Ads