home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / calendei / start2.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  1995-05-07  |  8.3 KB  |  262 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Calendar Form"
  6.    ClientHeight    =   3000
  7.    ClientLeft      =   435
  8.    ClientTop       =   2145
  9.    ClientWidth     =   5190
  10.    ControlBox      =   0   'False
  11.    Height          =   3405
  12.    Left            =   375
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   3000
  17.    ScaleWidth      =   5190
  18.    Top             =   1800
  19.    Width           =   5310
  20.    Begin CommandButton Command1 
  21.       Caption         =   "Draw New Date"
  22.       Height          =   315
  23.       Left            =   3540
  24.       TabIndex        =   5
  25.       Top             =   540
  26.       Width           =   1515
  27.    End
  28.    Begin CommandButton HelpButton 
  29.       Caption         =   "&Help"
  30.       Height          =   375
  31.       Left            =   3840
  32.       TabIndex        =   2
  33.       Top             =   2490
  34.       Width           =   915
  35.    End
  36.    Begin CommandButton CancelButton 
  37.       Cancel          =   -1  'True
  38.       Caption         =   "&Cancel"
  39.       Height          =   375
  40.       Left            =   3840
  41.       TabIndex        =   4
  42.       Top             =   1680
  43.       Width           =   915
  44.    End
  45.    Begin CommandButton OkButton 
  46.       Caption         =   "&OK"
  47.       Default         =   -1  'True
  48.       Height          =   375
  49.       Left            =   3840
  50.       TabIndex        =   3
  51.       Top             =   1080
  52.       Width           =   915
  53.    End
  54.    Begin TextBox CheckDate 
  55.       Height          =   315
  56.       Left            =   3540
  57.       MaxLength       =   10
  58.       TabIndex        =   1
  59.       Text            =   "12/30/90"
  60.       Top             =   120
  61.       Width           =   1275
  62.    End
  63.    Begin PictureBox P 
  64.       AutoRedraw      =   -1  'True
  65.       BackColor       =   &H0080FFFF&
  66.       FillStyle       =   0  'Solid
  67.       FontBold        =   -1  'True
  68.       FontItalic      =   0   'False
  69.       FontName        =   "Arial"
  70.       FontSize        =   8.25
  71.       FontStrikethru  =   0   'False
  72.       FontUnderline   =   0   'False
  73.       Height          =   2750
  74.       Left            =   180
  75.       ScaleHeight     =   7.913
  76.       ScaleMode       =   0  'User
  77.       ScaleWidth      =   8.339
  78.       TabIndex        =   0
  79.       Top             =   120
  80.       Width           =   3300
  81.    End
  82. 'Copyright 
  83.  by David F Eisenberg, 1994.
  84. 'This code is freeware.
  85. 'You are granted unlimited rights to modify or distribute this code for use in your compiled projects.
  86. 'You may NOT distribute this source code without this disclaimer.
  87. 'No warantees are stated or implied.
  88. Option Explicit
  89.     Dim DayName(7) As String 'stores names of days
  90.     Dim cRow As Integer 'Current Row
  91.     Dim cCol As Integer 'Current Column
  92.     Dim RowData(8, 7) As Double 'Saves Dates for each position if there is a date there.
  93.     Dim TDate As Double 'Saves date selected.
  94. 'Notes: The size of the picture box is critical. You may need to adjust the sizes if the
  95.     'marked dates do not display correctly. Change in increments of 1 twip until all spaces display correctly.
  96.     'The picture box as included should display corectly
  97. 'Changes you MUST make:
  98.     '1. Verify the date entered in the box and include a change event to triger a new calendar draw
  99.     '2. Create routines for the buttons
  100. 'Recomended changes:
  101.     '1. Add a spin button on the text box. You should verify the current date and reflect the changes
  102.         'in the calendar display by clearing the old marked box and going to the next or previous.
  103.         '(I did not include this because you may not have a spin control)
  104.     '2. Remove the Draw New Date button and replace its function. You may wish to respond
  105.         'to keypress commands or the above spin button.
  106. Sub CancelButton_Click ()
  107.     'put your cancel routine here
  108.     End
  109. End Sub
  110. Sub Command1_Click ()
  111.     DrawCal 'Draws the Calendar
  112. End Sub
  113. Sub DrawCal ()
  114.     'Draws the calendar
  115.     Dim it As Integer 'Counter
  116.     Dim iCol As Integer 'column counter for fill
  117.     Dim iRow As Integer ' "
  118.     Dim cDate As Double 'Date to mark
  119.     Erase RowData 'initialize the date data
  120.     P.Cls 'Clear the picture box
  121.     P.DrawWidth = 1
  122.     'The next lines scale the picture box so that the boxes can be accounted for
  123.     P.ScaleWidth = 7.02
  124.     P.ScaleHeight = 8.03
  125.     'Draw the lines
  126.     P.Line (0, 0)-(7, 1.3), &HFFFF00, BF
  127.     For it = 3 To 8
  128.         P.Line (0, it)-(7, it)
  129.     Next it
  130.     For it = 1 To 6
  131.         P.Line (it, 1.4)-(it, 8)
  132.     Next it
  133.         P.Line (0, 0)-(0, 8.03)
  134.         P.Line (7, 0)-(7, 8.03)
  135.     P.Line (0, 1.4)-(7, 1.4)
  136.     P.Line (0, 0)-(7, 0)
  137.     P.DrawWidth = 2
  138.     P.Line (0, 1.3)-(7, 1.3)
  139.     P.Line (0, 2)-(7, 2)
  140.     P.FontBold = True
  141.     P.CurrentY = 1.4
  142.     P.FontName = "Arial"
  143.     P.FontSize = 8.25
  144.     For it = 1 To 7
  145.         PrintPlace (it - .5), DayName(it)
  146.     Next it
  147.     'Draw the arrows
  148.     P.FontBold = True
  149.     P.FontSize = 16.5
  150.     P.CurrentY = .1
  151.     P.FontName = "WingDings"
  152.     PrintPlace .5, "
  153.     PrintPlace 6.5, "
  154.     P.FontName = "Arial"
  155.     TDate = DateValue(CheckDate.Text)
  156.     PrintPlace 3.5, Format$(TDate, "mmmm yyyy")
  157.     cDate = DateValue(Format$(TDate, "mmmm/1/yyyy")) 'Find 1st day of the month
  158.     iCol = Val(Format$(cDate, "w")) 'Find starting column
  159.     iRow = 3
  160.     P.CurrentY = 2#
  161.     P.FontSize = 14
  162.     Do 'Fill the calendar
  163.         PrintPlace iCol - .5, Format$(cDate, "d")
  164.         RowData(iRow, iCol) = cDate
  165.         If cDate = TDate Then
  166.             cRow = iRow
  167.             cCol = iCol
  168.         End If
  169.         iCol = iCol + 1
  170.         If iCol > 7 Then
  171.             iCol = 1
  172.             iRow = iRow + 1
  173.             P.CurrentY = P.CurrentY + 1
  174.         End If
  175.         cDate = cDate + 1
  176.     Loop Until Day(cDate) = 1 'Check if into the next month and stop
  177.     MarkPlace 'mark the test date in the box
  178. End Sub
  179. Sub Form_Load ()
  180.     'initialize daynames for calendar
  181.     DayName(1) = "Sun"
  182.     DayName(2) = "Mon"
  183.     DayName(3) = "Tue"
  184.     DayName(4) = "Wed"
  185.     DayName(5) = "Thu"
  186.     DayName(6) = "Fri"
  187.     DayName(7) = "Sat"
  188.     CheckDate.Text = Format$(Now, "m/d/yyyy")
  189.     DrawCal
  190. End Sub
  191. Sub HelpButton_Click ()
  192.     'call your help routine here
  193. End Sub
  194. Sub MarkPlace ()
  195.     P.DrawMode = 7 'XOR
  196.         P.Line (cCol - .93, cRow - .9)-(cCol - .04, cRow - .04), QBColor(14), BF
  197.     P.DrawMode = 13
  198. End Sub
  199. Sub OkButton_Click ()
  200.     'put your save routines here
  201.     End
  202. End Sub
  203. Sub P_MouseDown (button As Integer, Shift As Integer, x As Single, y As Single)
  204.     'The scale properties of the form are set to show x and y as calendar positions.
  205.     Dim r As Integer 'row
  206.     Dim c As Integer 'column
  207.     Dim m As Integer 'month
  208.     Dim yr As Integer 'year
  209.     Dim dy As Integer 'day
  210.     If y <= 1.3 Then
  211.         If x < 1 Then 'check to see if on one of the arrows
  212.             m = Month(TDate)
  213.             yr = Year(TDate)
  214.             dy = Day(TDate)
  215.             m = m - 1
  216.             If m = 0 Then
  217.                 m = 12
  218.                 yr = yr - 1
  219.             End If
  220.             TDate = DateSerial(yr, m, dy)
  221.             Do Until Day(TDate) = dy
  222.                 dy = dy - 1
  223.                 TDate = DateSerial(yr, m, dy)
  224.             Loop
  225.             CheckDate.Text = Format$(TDate, "m/d/yyyy")
  226.             DrawCal
  227.         ElseIf x > 6 Then
  228.             m = Month(TDate)
  229.             yr = Year(TDate)
  230.             dy = Day(TDate)
  231.             m = m + 1
  232.             If m > 12 Then
  233.                 m = 1
  234.                 yr = yr + 1
  235.             End If
  236.             TDate = DateSerial(yr, m, dy)
  237.             Do Until Day(TDate) = dy
  238.                 dy = dy - 1
  239.                 TDate = DateSerial(yr, m, dy)
  240.             Loop
  241.             CheckDate.Text = Format$(TDate, "m/d/yyyy")
  242.             DrawCal
  243.         End If
  244.         Exit Sub
  245.     End If
  246.     r = Int(y) + 1
  247.     c = Int(x) + 1
  248.     If RowData(r, c) Then
  249.         MarkPlace 'remove previous mark
  250.         cRow = r   'save location of new mark
  251.         cCol = c   '"
  252.         MarkPlace  'Place new mark
  253.         TDate = RowData(r, c) 'get new date
  254.         'print new date
  255.         CheckDate.Text = Format$(TDate, "m/d/yyyy")
  256.     End If
  257. End Sub
  258. Sub PrintPlace (x As Single, s As String)
  259.     P.CurrentX = x - P.TextWidth(s) / 2
  260.     P.Print s;
  261. End Sub
  262.