IsNumeric, Microsoft.VisualBasic.dll, etc.

Sean and Scott’s


earlier posting

on IsNumeric has resulted in a few comments…
and I just need to chime in here, use Microsoft.VisualBasic! It is all IL in the
end, right? This topic comes up over and over again on


GotDotNet

, and I just
want it to go away! Almost always, someone writes up and posts a C#
implementation of IsNumeric that might be useful, but it is not equivalent to
the function from this assembly. Why write your own, incorrect or incomplete,
implementation when a highly-tested one is shipping with the Framework? Are you
going to do the same for all of the functions in the Framework?

Microsoft.VisualBasic.dll is an assembly, it ships
with .NET, it provides useful functions… the decision to use it or not
shouldn’t be any more difficult than deciding if you are going to use any other
useful assembly. If you dig into the IL and you don’t like what it does, fine…
but I hope you are applying the same standard to all of the libraries you
use.

Counting lines of code…. why?


From time to time, when I’ve shown someone a
system I built, I’ve been asked “How many lines of code is that?”… and my
answer has always been the same… “I have no idea”.

I’ve never even tried to count the lines of code in a project, and I have no
idea why I would. Jason mentions in his post that some
people have to account for their lines of code produced in a day and I think
that is absolutely crazy. So if you write more lines of code, you are a more
productive employee? I hate to point out such an obvious point, but I’d like to
think that the important point is how many bugs you fixed or how many features
you completed…. regardless of how much typing it required.

Oh well, at least I don’t have to count my lines of code… and I don’t
intend to ever start. It is worth pointing out, since I am mostly a writer these
days, I don’t count the words in my articles (or pages) either. The exception
would be if I was being paid by the word, but as a general rule I don’t like to
pay or be paid by the word/page… pay me to cover a topic to a certain depth
and that should be enough. If I hand in 2 pages and you expected 20, read the
pages… did I cover the material, if not then don’t pay me… ok, now I am
rambling so I had better hit post…

 

Another little code snippet

Whenever I have to
code a “real” project, I end up building a bunch of components to deal with anything that seems
likely to reoccur
. Sometimes the class or Windows Forms control I’ve created
never gets used again, but often I end up using them in a whole bunch of
additional apps. Anyway, I think I’ll post some of these little bits of
development work to my blog when it seems useful enough, and perhaps other
developers will be able to find this code when they are looking for some help.

This particular piece of code is
pretty simple; it is just a small extension to the LinkLabel class to allow it
to handle launching the appropriate link when clicked.

 

     
public
class
ClickableLinkLabel : LinkLabel

     
{

 

        private string m_URL =
“about:blank”;

 

           
public
ClickableLinkLabel()

           
{

           
}

 

        protected override void OnLinkClicked

           
(LinkLabelLinkClickedEventArgs e)

       
{

           
ProcessStartInfo psi

               
=
new
System.Diagnostics.ProcessStartInfo(m_URL);

           
psi.UseShellExecute =
true;

           
System.Diagnostics.Process.Start(psi);

           
base.OnLinkClicked(e);

       
}

 

        /// <summary>

        /// Represents the link to
be navigated

        /// to when the label is
clicked

        /// </summary>

        public string
URL

       
{

           
get

           
{

               
return
m_URL;

           
}

           
set

            {

               
m_URL =
value;

           
}

       
}

     
}

 

 

 

Another MSDN TV episode!

Boy these are going
up fast…

A new episode featuring Omar Khan
from the Visual Studio .NET team has been posted. This is the second part to the
episode posted on Tuesday.

http://msdn.microsoft.com/msdntv/episode.aspx?xml=episodes/en/20030306VSNETOK/manifest.xml

Visual Studio
.NET Web Project Tips – Part 2

Get an explanation of different
ways to deploy your Visual Studio .NET Web applications to other machines. Omar
Khan discusses the easy way to use the “Copy Project” command, and also more
advanced methods such as creating a Web project setup.

Coding and Going to the Grocery Store

Greg Robinson’s comments today
were quite timely, I had been thinking much the same thing myself… Often, and
I find it happens more and more these days, I will go to find something on the
Internet, or buy something at the grocery store, and I end up doing everything
but the task I intended to accomplish. This appears to be normal human
behaviour, but it can be quite disturbing if you are short on time and have a
lot of things that need to get done. As Darren comments on Greg’s post, a
to-do list appears to be the only way to keep yourself focused. In coding this
is extremely important, so I use bug-tracking software to track new features and
bug fixes together with some priority info… otherwise I would code for a few
days and never get any closer to shipping out my application.

I suspect that we could all use more
focus to the work part of our day, the more productive we are at work, the more
we can goof-off at home! I’ve always wondered if there was a software solution
to this problem, but I think it much more of an issue with me than with any
particular means for tracking to-do’s. A piece of paper would likely be enough
of a “system” for tracking all of the things to do in a day, but like most
developers I feel compelled to at least use a computer solution (Outlook tasks
at the moment, at least they sync to my pda), although I have a strong desire to
write my own. I guess that would be the ultimate procrastination, writing your
own to-do list tool instead of actually working on the items on your
list.

Code Samples and VS.NET


Jimski



blogged about the IDE

the other day… since I am a writer for MSDN and
other places, this a topic that I’ve thought about quite a bit… sadly,
the only real solution seems to be posting code that works with both
situations (VS.NET and non-VS.NET) because posting code that doesn’t work well
in the Windows Forms designer is a bad-experience for people using VS.NET and
designer-generated code produces a bad experience for those who are not using
VS.NET.

Web Matrix makes this even more
interesting as now there are multiple IDEs from Microsoft that might require
different code samples/downloads to illustrate the same topic…

To me this is very similar to the idea
of posting code in both C# and VB.NET for every article… it is a good idea,
but I don’t always have the time to produce two versions, so I pick one. Same
with the IDE vs. no-IDE, I pick one… and actually I don’t always pick the same
one. It generally depends on what I am building and who it is for. VB.NET
programmers, in general, use the IDE, especially for Windows Forms, so I will
provide them with a project file and all that generated code.

On the other hand, the code I wrote for
the Dr.
GUI .NET columns
(I’m not Dr. GUI, I just write code for him sometimes) was
aimed at people trying to understand the framework, so it was written targetting
someone with a text editor and csc/vbc. I wish there were more times when it was
easy to do both, but that generally only happens when I do console or library
apps; I wrote some
MSMQ articles
for MSDN that had the vbc and csc command lines as a comment
in the first line of each code file, but also included a project file… and I
think that would have worked well for both “types” of people. I wrote lots of
code in my book
that was aimed at the command line compiler, in an attempt to keep it simple and
avoid confusing the beginning programmer with the IDE, but I think it was a
mistake; command line compiling just isn’t a good experience for a new developer
who isn’t used to it already.

What do you think I should do about
these issues (IDE and language, go ahead and fire away) for my
writing? And, while we are on a IDE-related topic, what about the visual
tools for building database code? I never use them, I never drag and drop a
connection, a data-adapter, or anything like it onto my Forms. So I never use
them in my articles. They seem cool enough though, and lots of people like
them… I’ve just had something against wizard-generated code ever since my Fox
Pro 2.6 days, and I think my internal “control-freak” is appeased by writing all
my data access code by hand… am I crazy? Should I use the tools, do you use
them?

DateTimePicker and DBNull



You can’t bind a Windows Forms DateTimePicker to a field
that might contain DBNull… so I did this;


 

      public class
DBDateTimePicker:DateTimePicker

     
{

 

           
public
DBDateTimePicker()

           
{

                 
//

                 
// TODO: Add constructor logic
here

                 
//

           
}

 

       
public object DBValue

       
{

           
get

           
{

               
if (this.Checked)

                   
return base.Value;

               
else

                   
return
System.DBNull.Value;

           
}

           
set

           
{

               
if (System.Convert.IsDBNull(value))

                    this.Checked=false;

               
else

                   
this.Value = Convert.ToDateTime(value);

           
}

       
}

     
}

 

Then I bind to “DBValue”  (instead of Value) and it appears to
work fine… if it is null, it is unchecked and disabled, otherwise it is enabled
and can be set to any normal date value… if you uncheck the box yourself, then
the data field is set to DBNull…

 

Not sure if it the best idea, but I can’t override Value so this
seems like a reasonable alternative… of course, I never looked around for the
“official” solution or any other possible answers, so let me know if you have a
better idea!

Grinding the Gears

Whenever I shut
down my laptop, it is a very painful experience… one by one I watch a
series of programs die a painful death, as they refuse to shut down gracefully.
The error messages about “Windows Stations” that are closing are very useful,
but somehow the entire process (which sometimes involves clicking a few “End
Task” buttons, and maybe even selecting Shut Down all over again because half of
my system is still breathing) reminds me a lot of watching someone you love
learning to drive with your stick-shift sportscar. You try to smile and focus on
the end result, but each event, each horrible noise or lurching movement, forces
a wince out of you.

I really like both of the “people”
involved (my laptop and Windows XP), but watching the horrible process that
occurs when I turn my machine off is almost enough to make me stick with standby
only from this point on.