What follows is the VBScript Code for the Due Date Calculator. The logic for drawing the calendar is translated from Dave Eisenberg's calendar. If you have any questions or comments about the code, contact me at .



<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
<!-- HIDE THE SCRIPT FROM OTHER BROWSERS

Function monthArray(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12)
  Dim this(11)
  this(0) = m1
  this(1) = m2
  this(2) = m3
  this(3) = m4
  this(4) = m5
  this(5) = m6
  this(6) = m7
  this(7) = m8
  this(8) = m9
  this(9) = m10
  this(10) = m11
  this(11) = m12
  monthArray = this
End Function

Function calcDueDate(menstDay)
  dim dueDate
  dueDate = DateSerial(year(menstDay),month(menstDay),day(menstDay)+280)
  calcDueDate = dueDate
End Function

function getMonthDays(day)
  dim mDays
  mDays = monthArray(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
  ' do the classic leap year calculation
  If (((Year(day) mod 4 = 0) and (Year(day) mod 100 <> 0)) or (Year(day) mod 400 = 0)) Then
     mDays(1) = 29
  End If
  dim numDays
  numDays = mDays(Month(day)-1)
  getMonthDays = numDays
End Function

Sub cboYears_Change
  setCboDays
End Sub

Sub cboMonths_Change
  setCboDays
End Sub

Function setCboDays
  dim Holder
  Holder = document.dateSetter.cboDays.ListIndex
  dim thisDay
  if document.dateSetter.cboYears.Value <> "" Then
    thisDay=DateSerial(document.dateSetter.cboYears.Value, (document.dateSetter.cboMonths.ListIndex + 1), 1)
  End If
  dim numDays
  numDays = getMonthDays(thisDay)
  document.dateSetter.cboDays.clear
  for i = 1 to numDays
  document.dateSetter.cboDays.additem i
  Next
  If Holder < numDays Then
    document.dateSetter.cboDays.ListIndex = Holder
  Else
    document.dateSetter.cboDays.ListIndex = numDays - 1
  End If
End Function

Sub SetCombos
  dim today
  today = Now

  dim thisYear
  thisYear = Year(today)
  If (thisYear < 100) Then
    thisYear = thisYear + 1900
  End If

  document.dateSetter.cboMonths.additem "January"
  document.dateSetter.cboMonths.additem "February"
  document.dateSetter.cboMonths.additem "March"
  document.dateSetter.cboMonths.additem "April"
  document.dateSetter.cboMonths.additem "May"
  document.dateSetter.cboMonths.additem "June"
  document.dateSetter.cboMonths.additem "July"
  document.dateSetter.cboMonths.additem "August"
  document.dateSetter.cboMonths.additem "September"
  document.dateSetter.cboMonths.additem "October"
  document.dateSetter.cboMonths.additem "November"
  document.dateSetter.cboMonths.additem "December"

  document.dateSetter.cboMonths.ListIndex = Month(today)-1

  document.dateSetter.cboYears.additem thisYear-1
  document.dateSetter.cboYears.additem thisYear
  document.dateSetter.cboYears.additem thisYear+1
  document.dateSetter.cboYears.additem thisYear+2
  document.dateSetter.cboYears.additem thisYear+3

  document.dateSetter.cboYears.value = thisYear

  setCboDays
  document.dateSetter.cboDays.value = Day(today)

End Sub

Sub btnCalc_OnClick
  Dim DueDay
  DueDay = calcDueDate(DateSerial(document.dateSetter.cboYears.Value, (document.dateSetter.cboMonths.ListIndex + 1), document.dateSetter.cboDays.Value) )
' add parameter get info.
  dim thisDay
  thisDay = Day(DueDay)
  dim thisYear
  thisYear = Year(DueDay)
' deal with two digit dates
  If (thisYear < 100) Then
    thisYear = thisYear + 1900
  End If
' now deal with that funky y2k problem
  If (thisYear < 1970) Then
    thisYear = thisYear + 100
  End If
  dim nDays
  nDays = getMonthDays(DueDay)
' and go back to the first day of the month...
  dim firstDay
firstDay = DateSerial(Year(DueDay), Month(DueDay), 1)
' and figure out which day of the week it hits...
  dim startDay
  startDay = WeekDay(firstDay)-1

  parent.Due.document.close()
  parent.Due.document.open()
  parent.Due.document.writeln("<CENTER>")
  parent.Due.document.writeln("<H2>YOUR DUE DATE IS</H2>")
  parent.Due.document.write("<TABLE BORDER>")
  parent.Due.document.write("<TR><TH COLSPAN=7>")
  parent.Due.document.write(document.dateSetter.cboMonths.List(Month(DueDay)-1))


  parent.Due.document.write(" ")
  parent.Due.document.write(thisYear)
  parent.Due.document.write("<TR><TH>Sun<TH>Mon<TH>Tue<TH>Wed<TH>Thu<TH>Fri<TH>Sat")
' now write the blanks at the beginning of the calendar
  parent.Due.document.write("<TR>")
  column = 0
  For i = 0 to startDay-1
    parent.Due.document.write("<TD>")
    column = column + 1
  Next
  For i = 1 to nDays
    parent.Due.document.write("<TD>")
    If (i = thisDay) Then
      parent.Due.document.write("<FONT COLOR=#FF0000>")
    End If
    parent.Due.document.write(i)
    If (i = thisDay) Then
      parent.Due.document.write("</FONT>")
    End If
    column = column + 1
    If (column = 7) Then
      parent.Due.document.write("<TR>") ' start a new row
      column = 0
    End If
  Next
  parent.Due.document.write("</TABLE>")
  parent.Due.document.writeln("</CENTER>")
  parent.Due.document.writeln("")
  parent.Due.document.close()

End Sub

' STOP HIDING FROM OTHER BROWSERS -->
</SCRIPT>

</HEAD>
<BODY lang=VBS ONLOAD="SetCombos">
<CENTER>
Select the first day of your last period:
<BR>
<FORM NAME="dateSetter">
  <OBJECT ID="cboMonths" WIDTH=137 HEIGHT=24
        CLASSID="CLSID:8BD21D30-EC42-11CE-9E0D-00AA006002F3">
    <PARAM NAME="VariousPropertyBits" VALUE="746604571">
    <PARAM NAME="DisplayStyle" VALUE="7">
    <PARAM NAME="Size" VALUE="3634;635">
    <PARAM NAME="MatchEntry" VALUE="1">
    <PARAM NAME="ShowDropButtonWhen" VALUE="2">
    <PARAM NAME="FontCharSet" VALUE="0">
    <PARAM NAME="FontPitchAndFamily" VALUE="2">
    <PARAM NAME="FontWeight" VALUE="0">
  </OBJECT>

  <OBJECT ID="cboDays" WIDTH=60 HEIGHT=24
           CLASSID="CLSID:8BD21D30-EC42-11CE-9E0D-00AA006002F3">
    <PARAM NAME="VariousPropertyBits" VALUE="746604571">
    <PARAM NAME="DisplayStyle" VALUE="7">
    <PARAM NAME="Size" VALUE="1588;635">
    <PARAM NAME="MatchEntry" VALUE="1">
    <PARAM NAME="ShowDropButtonWhen" VALUE="2">
    <PARAM NAME="FontCharSet" VALUE="0">
    <PARAM NAME="FontPitchAndFamily" VALUE="2">
    <PARAM NAME="FontWeight" VALUE="0">
  </OBJECT>

  <OBJECT ID="cboYears" WIDTH=137 HEIGHT=24
           CLASSID="CLSID:8BD21D30-EC42-11CE-9E0D-00AA006002F3">
    <PARAM NAME="VariousPropertyBits" VALUE="746604571">
    <PARAM NAME="DisplayStyle" VALUE="7">
    <PARAM NAME="Size" VALUE="3634;635">
    <PARAM NAME="MatchEntry" VALUE="1">
    <PARAM NAME="ShowDropButtonWhen" VALUE="2">
    <PARAM NAME="FontCharSet" VALUE="0">
    <PARAM NAME="FontPitchAndFamily" VALUE="2">
    <PARAM NAME="FontWeight" VALUE="0">
  </OBJECT>

  <INPUT TYPE=BUTTON VALUE="Calculate Due Date" NAME="btnCalc">
</FORM>

</CENTER>
</BODY>
</HTML>
return to geekstuff