Subscribe to Windows IT Pro
December 11, 2006 12:00 AM

Plan Ahead for Patch Tuesday

A script finds the date of the second Tuesday of each month or any such repeating day
Windows IT Pro
InstantDoc ID #94386
Rating: (1)
Downloads
94386.zip

Showing the Dates
The code at callout B determines whether to show one or multiple dates. If the user selected the Show check box (i.e., the Multimonth object), the code assigns the value stored in the NumOfMonths object to a variable called nofm and adds the value of Mth to that. You'll see the reason for that in a minute. If the Show check box isn't selected, the code stores the value of Mth in the nofm variable. Then the code stores the value of the current year in a variable called yr and gets ready to step into a looping routine.

The Looping Routine
The For Next routine (at callout C) is a little complicated, so bear with me as I step through it. I use x as my stepping variable name and Mth as my starting number. Remember that Mth contains the number of the month selected in the month drop-down box. For instance, if the user chose September, then the value of Mth is 9. My For Next ending point is nofm. As you'll recall, this variable holds a number equal to the month (Mth) number plus, if the Show box is selected, the number of consecutive months the user entered. Therefore, the For Next statement would look like the following if the user selected a combination of September, the Show check box, and six months:

For x = 9 to 15 

This technique lets me easily pass the selected month to the DLS function and continue to pass consecutive months. However, 15 doesn't sound like a value representing a month, does it? That's where the If logic checks at callout C come into play. Stepping through the code at callout C, you'll see that it uses the Mod function to determine whether x divided by 12 has a remainder of 1.

If the Mod function does have a remainder of 1 and x isn't equal to 1, then the code can safely assume that x is 13, 25, 37, 49, or some other multiple of 12, plus 1. This result in turn indicates that the function is moving into another year. So, the code adds 1 to the yr variable and sets the mm month variable to 1—in essence, January of the next year.

If x divided by 12 doesn't have a remainder of 1, the code checks whether x is greater than 12. If it is, the Mod function finds the month number. For example,

14 Mod 12 

returns a value of 2, which is assigned to mm and represents the month of February.

The next If statement determines whether the Mod function returned the value of 0. If it did, then the month is December and the mm value is set to 12. 12 Mod 12 returns 0, as does 24 mod 12, and so on. Finally, if x is less than 12, mm is assigned the value of x.

At this point, all the parameters are in place and can be passed to the DLS function. The final piece of the For Next routine puts the routine's return value(s) into a variable called SupTue. When all the cycles of the For Next loop are complete, the contents of SupTue are assigned to the application's listing object, which shows the user all the dates in his or her query.

I use HTA-SuperTuesday now not only to get a quick look at the dates for upcoming Super Tuesdays but also to remind me of events and meetings that I attend on first Fridays and second Wednesdays.

Related Content:

ARTICLE TOOLS

Comments
  • Test
    6 years ago
    Dec 28, 2006

    The zip file doesn't contain the code. It contains just the excerpt. And when I click the page 2 link on this webpage, page 2 doesn't exist.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.