home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / design / vbcal / calender.frm < prev    next >
Text File  |  1993-07-06  |  8KB  |  257 lines

  1. VERSION 2.00
  2. Begin Form Calender 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Calender"
  5.    ClientHeight    =   5685
  6.    ClientLeft      =   90
  7.    ClientTop       =   375
  8.    ClientWidth     =   6315
  9.    Height          =   6090
  10.    Left            =   30
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5685
  13.    ScaleWidth      =   6315
  14.    Top             =   30
  15.    Width           =   6435
  16.    Begin SSPanel Panel3D3 
  17.       AutoSize        =   3  'AutoSize Child To Panel
  18.       BackColor       =   &H00C0C0C0&
  19.       BevelOuter      =   1  'Inset
  20.       BorderWidth     =   8
  21.       Font3D          =   0  'None
  22.       Height          =   255
  23.       Left            =   3480
  24.       TabIndex        =   0
  25.       Top             =   4680
  26.       Width           =   1695
  27.       Begin Label DateField 
  28.          BackColor       =   &H00C0C0C0&
  29.          Height          =   225
  30.          Left            =   15
  31.          TabIndex        =   8
  32.          Top             =   15
  33.          Width           =   1665
  34.       End
  35.    End
  36.    Begin SSCommand GetDate 
  37.       Caption         =   "Pick a date"
  38.       Font3D          =   3  'Inset w/light shading
  39.       Height          =   555
  40.       Left            =   1200
  41.       TabIndex        =   7
  42.       Top             =   4500
  43.       Width           =   1455
  44.    End
  45.    Begin SSPanel CalenderForm 
  46.       Alignment       =   8  'Center - BOTTOM
  47.       BackColor       =   &H00C0C0C0&
  48.       BevelOuter      =   1  'Inset
  49.       BorderWidth     =   8
  50.       Caption         =   "Double click on a date to select"
  51.       Font3D          =   1  'Raised w/light shading
  52.       Height          =   2835
  53.       Left            =   960
  54.       TabIndex        =   1
  55.       Top             =   660
  56.       Visible         =   0   'False
  57.       Width           =   4215
  58.       Begin SSPanel Panel3D1 
  59.          Alignment       =   8  'Center - BOTTOM
  60.          AutoSize        =   3  'AutoSize Child To Panel
  61.          BackColor       =   &H00C0C0C0&
  62.          BevelOuter      =   1  'Inset
  63.          BorderWidth     =   8
  64.          Font3D          =   1  'Raised w/light shading
  65.          Height          =   255
  66.          Left            =   120
  67.          TabIndex        =   9
  68.          Top             =   60
  69.          Width           =   1455
  70.          Begin Label DateCaption 
  71.             BackColor       =   &H00C0C0C0&
  72.             Height          =   225
  73.             Left            =   15
  74.             TabIndex        =   6
  75.             Top             =   15
  76.             Width           =   1425
  77.          End
  78.       End
  79.       Begin SSPanel Panel3D2 
  80.          BackColor       =   &H00C0C0C0&
  81.          BevelOuter      =   1  'Inset
  82.          BorderWidth     =   8
  83.          Font3D          =   0  'None
  84.          Height          =   495
  85.          Left            =   120
  86.          TabIndex        =   3
  87.          Top             =   2100
  88.          Width           =   3975
  89.          Begin SSCommand Previous 
  90.             Caption         =   "Previous Month"
  91.             Font3D          =   3  'Inset w/light shading
  92.             Height          =   375
  93.             Left            =   240
  94.             TabIndex        =   5
  95.             Top             =   60
  96.             Width           =   1695
  97.          End
  98.          Begin SSCommand Next 
  99.             Caption         =   "Next Month"
  100.             Font3D          =   3  'Inset w/light shading
  101.             Height          =   375
  102.             Left            =   2040
  103.             TabIndex        =   4
  104.             Top             =   60
  105.             Width           =   1695
  106.          End
  107.       End
  108.       Begin Grid Calender 
  109.          BackColor       =   &H0000FFFF&
  110.          Cols            =   7
  111.          FixedCols       =   0
  112.          Height          =   1695
  113.          Left            =   120
  114.          Rows            =   7
  115.          ScrollBars      =   0  'None
  116.          TabIndex        =   2
  117.          Top             =   360
  118.          Width           =   3975
  119.       End
  120.    End
  121. End
  122. Option Explicit
  123.  
  124. ' Create module global variables
  125. Dim mgiCurrentMonth As Integer
  126. Dim mgiCurrentYear As Integer
  127. Dim mgiCurrentDay As Integer
  128. Dim mgiStartMonth As Integer
  129. Dim mgiStartDay As Integer
  130. Dim mgiStartYear As Integer
  131. Dim mgiStartDOW As Integer ' What day of the week does the 1st fall on
  132. Dim mgiLastDOW As Integer  ' What is the last day of the week
  133. Dim mgsDayNames(0 To 6) As String * 3   ' The names of the days. Change this for different languages
  134. Dim mgsPickDate As String ' This is the global variable used to transfer the date in
  135.  
  136. Sub Calender_DblClick ()
  137. Dim s As String
  138.  
  139.     If Calender.Text <> "" And Calender.CellSelected = True Then
  140.         ' Put the date in a module global varible to be picked up elsewhere
  141.         mgsPickDate = Calender.Text + "/" + Str$(mgiCurrentMonth) + "/" + Str$(mgiCurrentYear)
  142.     End If
  143.  
  144. End Sub
  145.  
  146. Sub DoCalender (lsStartDate As Variant)
  147. Dim lsStartString As String, liX As Integer, liY As Integer
  148.  
  149.     ' Find the first day of the week for the month
  150.     mgiStartMonth = Month(lsStartDate)
  151.     mgiCurrentMonth = mgiStartMonth
  152.     mgiStartYear = Year(lsStartDate)
  153.     mgiCurrentYear = mgiStartYear
  154.     mgiCurrentDay = Day(lsStartDate)
  155.     lsStartString = "1/" + Str$(mgiStartMonth) + "/" + Str$(mgiStartYear)
  156.     mgiStartDOW = Weekday(Format$(lsStartString, "dd/mm/yyyy"))
  157.     DateCaption.Caption = Format$(lsStartDate, "mmmm yyyy")
  158.     
  159.     On Error Resume Next
  160.     For liX = 27 To 32
  161.         lsStartString = Str$(liX) + "/" + Str$(mgiStartMonth) + "/" + Str$(mgiStartYear)
  162.         liY = Weekday(Format$(lsStartString, "dd/mm/yyyy"))
  163.         If Err <> 0 Then
  164.             Err = 0
  165.             Exit For
  166.         End If
  167.     Next liX
  168.     mgiLastDOW = liX - 1
  169.  
  170.     ' Clear out the calender to remove any previous data
  171.     For liX = 0 To 6
  172.         For liY = 1 To 6
  173.             Calender.Col = liX
  174.             Calender.Row = liY
  175.             Calender.Text = ""
  176.         Next liY
  177.     Next liX
  178.  
  179.     ' Now fill in the dates
  180.     Calender.Col = mgiStartDOW - 1 ' Weekdays go 1 to 7, cols go 0 to 6
  181.     Calender.Row = 1
  182.     For liX = 1 To mgiLastDOW
  183.         Calender.Text = liX
  184.         liY = Calender.Col + 1
  185.         If liY = 7 Then
  186.             Calender.Col = 0
  187.             Calender.Row = Calender.Row + 1
  188.         Else
  189.             Calender.Col = Calender.Col + 1
  190.         End If
  191.     Next liX
  192.  
  193.  
  194. End Sub
  195.  
  196. Sub Form_Load ()
  197. Dim liX As Integer
  198.  
  199.     mgsDayNames(0) = "Sun"
  200.     mgsDayNames(1) = "Mon"
  201.     mgsDayNames(2) = "Tue"
  202.     mgsDayNames(3) = "Wed"
  203.     mgsDayNames(4) = "Thu"
  204.     mgsDayNames(5) = "Fri"
  205.     mgsDayNames(6) = "Sat"
  206.  
  207.     ' Set up the calender days
  208.     Calender.Row = 0
  209.     For liX = 0 To 6
  210.         Calender.Col = liX
  211.         Calender.ColAlignment(liX) = 2
  212.         Calender.Text = mgsDayNames(liX)
  213.     Next liX
  214.  
  215. End Sub
  216.  
  217. Sub GetDate_Click ()
  218.     
  219.     GetDate.Enabled = False
  220.     CalenderForm.Visible = True
  221.     mgsPickDate = ""   ' For this demonstration we just test for the date string being there
  222.     DoCalender Now
  223.     Do While mgsPickDate = ""
  224.         DoEvents
  225.     Loop
  226.     CalenderForm.Visible = False
  227.     DateField.Caption = Format$(mgsPickDate, "dd-mmm-yyyy") ' Display the date
  228.     GetDate.Enabled = True
  229.  
  230. End Sub
  231.  
  232. Sub Next_Click ()
  233. Dim ls As String
  234.  
  235.     mgiCurrentMonth = mgiCurrentMonth + 1
  236.     If mgiCurrentMonth = 13 Then
  237.         mgiCurrentMonth = 1
  238.         mgiCurrentYear = mgiCurrentYear + 1
  239.     End If
  240.     ls = Str$(mgiCurrentDay) + "/" + Str$(mgiCurrentMonth) + "/" + Str$(mgiCurrentYear)
  241.     DoCalender ls
  242.  
  243. End Sub
  244.  
  245. Sub Previous_Click ()
  246. Dim ls As String
  247.  
  248.     mgiCurrentMonth = mgiCurrentMonth - 1
  249.     If mgiCurrentMonth = 0 Then
  250.         mgiCurrentMonth = 12
  251.         mgiCurrentYear = mgiCurrentYear - 1
  252.     End If
  253.     ls = Str$(mgiCurrentDay) + "/" + Str$(mgiCurrentMonth) + "/" + Str$(mgiCurrentYear)
  254.     DoCalender ls
  255. End Sub
  256.  
  257.