Scripting Central--Wishful Thinking--December 2, 2005

See whether any of these wishes are on your holiday wish list and learn about the LeapYear function--the second winner of the My Favorite Function contest.

ITPro Today

December 1, 2005

11 Min Read
ITPro Today logo in a gray background | ITPro Today

DOWNLOAD THE CODE:
48649.zip

1. Perspectives

  • Wishful Thinking

2. Scripter's Toolkit

  • LeapYear Function Might Have You Leaping for Joy

3. This & That

  • There's Still Time to Enter the "My Favorite Function" Contest

4. Script Watch

  • The Good, Better, and Best Ways to Obtain Constants and Their Values

5. Events and Resources

  • Get the Most from Reporting Services

  • Get the Facts About Deploying SQL Server 2005!

  • Plan and Implement Highly Available Exchange Systems

  • Are You Really Prepared for Disaster Recovery?

  • Upgrade to Analysis Services 2005

6. Featured White Paper

  • Integrating Fax Servers in MFP Environments

7. Announcements

  • Want to Become a VIP Subscriber?

8. New & Improved

  • Automation Without Writing a Single Line of Code

1. Perspectives
by Karen Bemowski, [email protected]

Wishful Thinking
With the holiday season fast approaching, many of us are getting our wish lists ready. If holiday magic could deliver all that we ask for, here's what a scripter's wish list might look like:

  • Objects of My Affection: The Big Book of Object Models. Wouldn't it be nice to have a definitive book that documents every object model imaginable, including all the properties, methods, and constants and their values for each object? This book would not only be an invaluable resource but also help bulk up your biceps.

  • A customized Scriptomatic utility that you don't have to create yourself. The Microsoft Scripting Guys' Scriptomatic 2.0--a utility that writes WMI scripts for you--has been a big hit with and a big help to scripters. However, it would be even nicer to have a Scriptomatic utility customized to your specific needs. This week's "The Scripting Eye for the GUI Guy" column on the Microsoft Script Center discusses how you can build your own custom Scriptomatic utility. However, if you can create a customized Scriptomatic utility, you probably don't need this type of tool to help you write a script. I guess we're going to have to rely on holiday magic for this one.

  • The Handy Dandy Pocket Automatic Translator. Wouldn't it be nice to have a gizmo that automatically translates what you say about your scripts into words and concepts that nonscripters would understand? That way, when you're about to talk with a nontechnical manager, end user, friend, or loved one about your latest scripting masterpiece, you could reach into your pocket, take out the Handy Dandy Pocket Automatic Translator, and talk about your script without their eyes glazing over as your words whiz past their ears.

  • The IT Teleporter. Scripters and other IT professionals are often asked to take on more and more responsibilities, making the workday longer and longer. Wouldn't it be nice to have a teleportation device that could instantly transport you from your office to a remote location across the country or even across the world? That way, if a remote server was having a scripting or other problem, you could teleport over there, fix the problem, and teleport back all before it was time for the evening commute home--via teleporter, of course.

  • World peace and the end to world hunger. As long as we're wishing, we might as well wish big and wish for the end of conflict and hunger throughout the world. In fact, I'm sure most scripters would gladly tear up their lists if holiday magic could make this one wish come true.

With that thought, let me be one of the first people to wish you a happy holiday season. Be safe, be kind, and be there for your family and friends.

2. Scripter's Toolkit

Editor's note: Jim Turner is the second winner of the "My Favorite Function" contest. His VBScript function named LeapYear determines whether the specified year is a leap year. For information about how to enter your favorite VBScript or JScript function in this contest, see the "This and That" section.

LeapYear Function Might Have You Leaping for Joy
The LeapYear function can be a handy little snippet when you code date logic, particularly if you have a user-provided start or end date. For most months, it's relatively simple to determine a valid day entry by checking the maximum number of days in a specific month. You could evaluate the number of days with a simple Select Case statement. The value would be either 30 or 31. If a user entered April 31, for instance, the Select Case statement could correct it to April 30.

But there always seems to be an exception to the rule. In this case, it's the coldest of all months (at least where I'm from): February. Determining the number of days in February requires a little more work.

The simplest way I have found to evaluate February is to get the "day number" for March 1. For example, January 1 is day number 1 and February 1 is day number 32. March 1 is day number 60 in a nonleap year and day number 61 in a leap year.

Here's the code for the function:

   Function LeapYear (pYr)      On Error Resume Next      chkdate = CDate(pYr & "/" & "03" & "/" & "01")      daynum = DatePart("y",chkdate)      If Err  0 Then         Exit Function      End If       If daynum > 60 Then         LeapYear = True      Else         LeapYear = False      End If   End Function 

The LeapYear function takes one argument: any year from 0 to 9999. The LeapYear function concatenates that year with March 1, converts the resulting string to a Date type value using VBScript's CDate function, and assigns that date value to a variable named chkdate. VBScript's DatePart function then uses its "y" parameter (which indicates a time interval of "day of year") along with the chkdate variable to return the day number for March 1 of the given year.

If the user provides in an invalid date, both the CDate and DatePart functions throw an error, which prompts the function to exit. If the user provides a valid date, the day number is evaluated. If the day number is greater than 60, the LeapYear function returns True (i.e., the year is a leap year). Otherwise, the LeapYear function returns False.

Here's how you might use the LeapYear function in a script:

   yr = InputBox("Enter Year", "Valid Years 0 to 9999")    If LeapYear(yr) Then       MsgBox "Is a Leap Year"    Else       If Err  0 Then          MsgBox "Invalid Input... "          Err.Clear       Else          MsgBox "Not a Leap Year"       End If    End If    Function LeapYear (pYr)      On Error Resume Next      chkdate = CDate(pYr & "/" & "03" & "/" & "01")      daynum = DatePart("y",chkdate)      If Err  0 Then         Exit Function      End If      If daynum > 60 Then         LeapYear = True      Else         LeapYear = False      End If   End Function 

This script uses a simple input box to get a year from the user. You can also use the LeapYear function within an HTML Application (HTA). You can download a sample HTA, LeapYearFunctionDemo.hta, by going to http://www.windowsitpro.com/windows/article/articleid/48649/48649.html and clicking the 48649.zip hotlink.

-- Jim Turner

3. This & That

There's Still Time to Enter the "My Favorite Function" Contest
Have you written a VBScript or JScript function that you constantly use in your scripts? Does this function require little or no modification each time you use it, so all you basically have to do is call it into action? If so, submit your VBScript or JScript function to Scripting Central's "My Favorite Function" contest.

Three winners will be chosen (one a month for 3 months), each of which will receive $100 and get his or her function published in Scripting Central and in Windows Scripting Solutions' "Snippets to Go" column. In addition, the three winners will be put into a drawing for another $100. We have one winner so far (see the "Scripter's Toolkit" section).

To enter the contest, send a description of what your VBScript or JScript function does and how to use it in a script (e.g., how to call it). In addition, include the function code. You can email your entry to [email protected]. Please include your full name and telephone number. Look for the third month's winner in the January 6 edition of Scripting Central.

4. Script Watch

The Good, Better, and Best Ways to Obtain Constants and Their Values
The COM technology behind objects such as the Microsoft Scripting Runtime Library's FileSystemObject object and Windows Script Host's (WSH's) WshShell object is what makes WSH scripts so powerful. However, the way this technology works causes scripters significant grief in one area: Scripts don't get access to the crucial constants embedded in objects. Learn about several ways to obtain those crucial values in Alex K. Angelopoulos' article "How to Find Constants and Their Values" in the January 2006 issue of Windows Scripting Solutions.

5. Events and Resources

Get the Most from Reporting Services
In this free Web seminar, you'll learn about innovative ways to extend your reports, reporting from XML-based data, delivering reports with the new Report Viewer, supercharging reports with SQL Server 2005 CLR stored procedures, and more! Register today:
http://www.windowsitpro.com/go/seminars/reportingservices/?parterref=1123emailannc

Get the Facts About Deploying SQL Server 2005!
SQL Server experts will present real-world information about administration, development, and business intelligence to help you put SQL Server 2005 into practice and how to use its new capabilities to improve your database-computing environment. Receive a one-year membership to PASS and one-year subscription to SQL Server Magazine. Register now at:
http://www.windowsitpro.com/roadshows/sqlservereurope/index.cfm?code=1130emailannc

Plan and Implement Highly Available Exchange Systems
Learn about the concepts behind high availability Exchange server planning. Plus, discover how to properly assess the business drivers that affect how you craft your Service Level Agreements. You'll get the tips you need to understand the various options available to you for planning and implementing highly available Exchange systems including: Fault Tolerant design, clustering and what uptime really means! Register today at:
http://www.windowsitpro.com/go/seminars/exchange/?partnerref=1130emailannc

Are You Really Prepared for Disaster Recovery?
Join industry guru Liam Colvin in this free Web seminar and get the tips you need to validate your disaster recovery data. You'll learn if your backup and restore data is worth staking your career on, what type of geo-clustering is right for you, which response to use in crisis situations, and more!
http://www.windowsitpro.com/go/seminars/disasterrecovery/?partnerref=1130emailannc

Upgrade to Analysis Services 2005
Get the tips and tricks you'll need to upgrade to Analysis Services 2005, including possible upgrade and migration scenarios, pre-planning steps, running the new Analysis Services migration wizard, and more. Plus discover what steps need to be completed after the migration process is complete and explore some of the new features of Analysis Services 2005.
http://www.windowsitpro.com/go/seminars/analysisservices/?partnerref=1130emailannc

6. Featured White Paper

Integrating Fax Servers in MFP Environments
Did you know that wasteful processes can drive the cost of document management and output to as high as 10-15% of your company's annual revenues? Download this free white paper today and find out how you can use fax solutions to achieve cost control, security and compliance, increased workflow and more.
http://www.windowsitpro.com/go/whitepapers/Faxback/faxing?code=1130emailannc

7. Announcements

Want to Become a VIP Subscriber?
Become a VIP subscriber and get continuous, inside access to ALL of the online resources published in Windows IT Pro magazine, SQL Server Magazine, Exchange and Outlook Administrator newsletter, Windows Scripting Solutions newsletter, and Windows IT Security newsletter – that's over 26,000 articles at your fingertips. You will also get a valuable one-year print subscription to Windows IT Pro and two VIP CDs (includes the entire article database on CD, delivered twice per year). Don't miss out...sign up now:
https://store.pentontech.com/index.cfm?s=1&promocode=eu275cuv

8. New and Improved

Automation Without Writing a Single Line of Code
Network Automation released AutoMate 6, software that automates business processes, regardless of their complexity. Without writing any code, you can automate a wide variety of network and computing operations, including FTP file transfers, event log monitoring, data or file replication, and SQL database transactions. After you build tasks through drag-and-drop operations, you can deploy the tasks in-place with event-based triggers or deploy tasks across the enterprise to other AutoMate installations with only a few mouse clicks. AutoMate tasks are displayed in plain-English sentences. Automate 6 has many new features, including more than 20 new actions, support for Secure HTTP (S-HTTP) and Secure FTP, and integration with Microsoft Excel. For more information, contact Network Automation at (213) 738-1700, (888) 786-4796, or [email protected].
http://www.networkautomation.com

Contact Us

This email newsletter is brought to you by Windows IT Pro, the leading publication for IT professionals deploying Windows and related technologies. Subscribe today!
https://store.pentontech.com/index.cfm?s=1&promocode=eu205xfb

View the Windows IT Pro Privacy Policy.
http://www.winnetmag.com/aboutus/index.cfm?action=privacy

Windows IT Pro is a division of Penton Media, Inc. 221 East 29th Street, Loveland, CO 80538, Attention: Customer Service Department

Copyright 2005, Penton Media, Inc. All Rights Reserved.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like