Jan Schreuder on .Net

.Net code samples, experiences, observations

View my professional profile on LinkedIn

Recent Posts

Tags

News

  • Inappropriate comments will be deleted at my discretion.

    The information and code samples in this weblog is provided "AS IS" without warranty of any kind, either expressed or implied, including but not limited to the merchantability and/or fitness for a particular purpose.

Community

Email Notifications

Tool suppliers

Tools

General

Microsoft

Favorite blogs

Archives

November 2004 - Posts

Number of working days

I needed a method to calculate the number of working days between two specified dates. I scanned the internet and found a VBA example in the Microsoft knowledge base. I needed a C# version, so below is the converted code for those who are interested:

long WorkingDays(DateTime beginDate, DateTime endDate)
{
TimeSpan   span = endDate.Subtract(beginDate);
   long        wholeWeeks = ((long)Math.Round(Math.Floor(span.TotalDays))) / 7;
   DateTime   dateCount  = beginDate.AddDays(wholeWeeks * 7);
   int         endDays   = 0;


       
while (dateCount.Date <= endDate.Date)
   {
   switch (dateCount.DayOfWeek)
      {
      case DayOfWeek.Saturday:
         case DayOfWeek.Sunday:
         break;
         default:
         endDays++;
         break;
         }
         dateCount = dateCount.AddDays(1);
}
   return wholeWeeks * 5 + endDays;
}
 
WebMessenger is here

I've used it the last couple of months while it was still in the beta-phase. And I guess most of you already knew it existed. But Microsoft has today officially released MSN WebMessenger. For those of you behind a proxy-server or fire-wall that does not allow you to run the 'old' messenger, you can finally get online.

Posted: Nov 18 2004, 12:55 PM by Jan Schreuder
Filed under:
The 10 Rules Of Performance

Yesterday, I read the article “The 10 Rules Of Performance”,  written by Paul Vick. He sums up 10 rules you should keep in mind when looking at performance in application development. If you like to know what he thinks, read the article. It's a good read. His rules apply to any language, not just VB.Net (which he blogs about). I recognised a lot of the things he mentioned.

The 10 rules according to Paul Vick:

  1. Don’t assume you know anything.
  2. Never take your eyes off the ball.
  3. Be afraid of the dark.
  4. Assume things will always get worse.
  5. Problems have to be seen to be believed (or: profile, profile, profile).
  6. 90% of performance problems are designed in, not coded in.
  7. Performance is an iterative process.
  8. You’re either part of the solution or part of the problem.
  9. It’s the memory, stupid.
  10. Don't do anything unless you absolutely have to.
Off topic

Posted: Nov 09 2004, 02:09 PM by Jan Schreuder
Filed under:
Paste as HTML
It you're like me and like to copy code from Visual Studio into your BLOG, you might want to check out this utility. It adds a 'Copy as HTML' option to the context menu in your code. To use it, simply mark the code you want to copy and right-click.
Posted: Nov 08 2004, 08:46 AM by Jan Schreuder | with 2 comment(s)
Filed under:
Using VB.Net in C# ?

A few months back I posted a short item about using the VB.Net run-time to check values. I did this so I could use the IsNumeric method. I could have written it myself using a try/catch construct, but try/catch comes at a performance cost. And I figured Microsoft would have a more complete check.

Today I looked at the disassembly for IsNumeric using Lutz Roeder's Reflector and discovered that the check incorporated a try/catch construct that I was actually trying to avoid :-). So should I continue to use the VB.Net runtime in my C# application?

Yes, I do. Why? For one, it works and is used by loads of VB.Net developers around the world. Second, have a look at the disassembly for the IsNumeric method. I would not think of writing this myself.

Update 8-11-2004

Pascal Naber sent me this link comparing the IsNumeric option with try/catch, double.Parse, regular expression checking and some other options. The author concludes that the fastest way to check for numeric strings is double.Parse, closely followed by the IsNumeric option from VB.Net! When you look at the disassembly for IsNumeric, you will see it will actually do double.Parse and some other checks. Best of all, IsNumeric and double.Parse are upto 15 times faster than a try/catch around a Convert.ToDouble! And almost twice as fast as a regular expression check.

ASP.Net dialogboxes

Surfing the web trying to find a solution for my friends dialogbox problem, I came across this link which offers a commercial solution to the problem. The component provides a client-side dialogbox at a reasonable price, $29. The site offers a demo of all the features.

All I can say is, why isn't there a standard MessageBox for ASP.Net in Visual Studio?

Posted: Nov 04 2004, 02:03 PM by Jan Schreuder | with 1 comment(s)
Filed under:
ASP.Net and JavaScript

I haven't done anything with ASP.Net in the past year, but when a friend asked me if I could help him do something very simple I obviously jumped in to help him. So what was that simple task, you may wonder?

Well, he needed a messagebox asking the user “Do you really want to delete this?”. And then, suddenly, Microsoft can only offer to use JavaScript?!?!?

It's not that difficult but I must admit it took me longer than I thought to come up with the answer. And I just know that I will have forgotten by the time I need it again. So here is my solution to the 'problem'. Simply drop this in your HTML and see that it works.

<HTML>
   <body>
      <form name="myForm">
         <script language="JavaScript">
         <!--
         function displayPopup() 
         {
            if (confirm("Do you really want to delete this"))
              
myForm.myTextBox.value = 'You clicked OK' ;
            else
               
myForm.myTextBox.value = 'You clicked Cancel' ;
         }
         
// -->
         </
script>
         <input type="button" onclick="displayPopup()" value="Click Me!">
         <input type="text" id="myTextBox">
      <form
>
   <body
>
<HTML
>

Sources used:

  1. Working with Client-Side scripts, Scott Mitchel, MSDN
  2. Implement Client Scripts, Visual Studio Magazine

Update: 5-Nov-2004.

Instead of useful comments, all I got was people telling me it was simple and straightforward. I knew that already, so I disabled posting comments to this entry.