home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_1 / DT01 / DT01.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-12-02  |  15.3 KB  |  375 lines

  1. VERSION 2.00
  2. Begin Form frmCalendar 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00C0C0C0&
  5.    BorderStyle     =   0  'None
  6.    ClientHeight    =   1020
  7.    ClientLeft      =   1332
  8.    ClientTop       =   1704
  9.    ClientWidth     =   1956
  10.    ForeColor       =   &H00000000&
  11.    Height          =   1440
  12.    Left            =   1284
  13.    ScaleHeight     =   1020
  14.    ScaleWidth      =   1956
  15.    Top             =   1332
  16.    Width           =   2052
  17.    Begin SSRibbon gpMonthSpin 
  18.       BackColor       =   &H00C0C0C0&
  19.       BevelWidth      =   0
  20.       Height          =   252
  21.       Index           =   2
  22.       Left            =   1320
  23.       Outline         =   0   'False
  24.       PictureDnChange =   2  'Invert 'PictureUp' Bitmap
  25.       PictureUp       =   DT01.FRX:0000
  26.       Top             =   120
  27.       Width           =   300
  28.    End
  29.    Begin SSRibbon gpMonthSpin 
  30.       BackColor       =   &H00C0C0C0&
  31.       BevelWidth      =   0
  32.       Height          =   252
  33.       Index           =   1
  34.       Left            =   360
  35.       Outline         =   0   'False
  36.       PictureDnChange =   0  'Use 'PictureUp' Bitmap Unchanged
  37.       PictureUp       =   DT01.FRX:0686
  38.       RoundedCorners  =   0   'False
  39.       Top             =   120
  40.       Width           =   300
  41.    End
  42.    Begin PictureBox pic 
  43.       AutoRedraw      =   -1  'True
  44.       BackColor       =   &H00C0C0C0&
  45.       BorderStyle     =   0  'None
  46.       FontTransparent =   0   'False
  47.       ForeColor       =   &H00000000&
  48.       Height          =   372
  49.       Left            =   480
  50.       ScaleHeight     =   372
  51.       ScaleWidth      =   372
  52.       TabIndex        =   0
  53.       Top             =   480
  54.       Width           =   372
  55.    End
  56.    Begin Timer TmrMonthSpin 
  57.       Enabled         =   0   'False
  58.       Interval        =   200
  59.       Left            =   1320
  60.       Top             =   480
  61.    End
  62.    Begin Label lblMonthText 
  63.       Alignment       =   2  'Center
  64.       BackColor       =   &H00C0C0C0&
  65.       Caption         =   "lMonth"
  66.       Height          =   192
  67.       Left            =   720
  68.       TabIndex        =   1
  69.       Top             =   120
  70.       Width           =   564
  71.    End
  72. Option Explicit
  73.     ' Create form level globals?
  74.     Dim nCurrentYear As Integer
  75.     Dim nCurrentMonth As Integer
  76.     Dim nCurrentDay As Integer
  77.     Dim nStartDay As Integer
  78.     Dim nTotalDays As Integer
  79.     Dim nBlockNdx As Integer
  80.     Dim nCopyBlockNdx As Integer
  81.     Dim nBlockHeight As Integer
  82.     Dim nWidth As Integer
  83.     Dim nHeight As Integer
  84. Sub Form_Activate ()
  85.     ' Initialize form level date variables.
  86.     ' -------------------------------------
  87.     If IsDate(gDate) Then
  88.         nCurrentYear = Year(gDate)
  89.         nCurrentMonth = Month(gDate)
  90.         nCurrentDay = Day(gDate)
  91.     Else
  92.         nCurrentYear = Year(Now)
  93.         nCurrentMonth = Month(Now)
  94.         nCurrentDay = Day(Now)
  95.     End If
  96.     ' print days of the month.
  97.     ' ------------------------
  98.     PrintMonth
  99. End Sub
  100. '================================================
  101. ' = Get all the static non-moving bits out here =
  102. '================================================
  103. Sub Form_Load ()
  104.     Dim i As Integer
  105.     Dim nOldWidth As Integer
  106.     ' Set width/height of one char.
  107.     ' -----------------------------
  108.     nWidth = TextWidth("M") ' Change this for bigger/smaller calendars.
  109.     nHeight = nWidth * 1.9
  110.     ' resize the form.
  111.     ' ----------------
  112.     Me.Height = (nHeight * 6) + (nHeight * .75)
  113.     Me.Width = ((nWidth * 2) * 7) + (nWidth * 1.25)
  114.     ' position left/right arrows.
  115.     ' ---------------------------
  116.     gpMonthSpin(1).Top = nHeight / 4
  117.     gpMonthSpin(2).Top = nHeight / 4
  118.     gpMonthSpin(1).Left = nWidth / 2
  119.     gpMonthSpin(2).Left = Width - gpMonthSpin(1).Width - (nWidth / 2)
  120.     ' position month label between l/r arrows.
  121.     ' ----------------------------------------
  122.     lblMonthText.Top = nHeight / 4
  123.     lblMonthText.Left = gpMonthSpin(1).Left + gpMonthSpin(1).Width
  124.     lblMonthText.Width = gpMonthSpin(2).Left - lblMonthText.Left
  125.     ' size background panel.
  126.     ' ----------------------
  127.     pic.Top = (nHeight * 2.25)
  128.     pic.Left = (nWidth / 2)
  129.     pic.Width = ((nWidth * 2) * 7) + 20
  130.     pic.Height = (nHeight * 4) + 50
  131.     ' Output Day text.
  132.     ' ----------------
  133.     For i = 1 To 7
  134.         CurrentY = nHeight * 1.25
  135.         CurrentX = (i * (nWidth * 2)) - (nWidth * 1.5)
  136.         Print Mid$("SuMoTuWeThFrSa", i * 2 - 1, 2)
  137.     Next
  138.     ' draw separator line + shadow.
  139.     ' -----------------------------
  140.     Line (0, nHeight * 2)-(Width, nHeight * 2), QBColor(0)
  141.     Line (0, nHeight * 2 + (nHeight / 29))-(Width, nHeight * 2 + (nHeight / 29)), QBColor(15)
  142.     ' Attempt at a 3D border.
  143.     ' -----------------------
  144.     nOldWidth = Me.DrawWidth
  145.     Me.DrawWidth = 10
  146.     Me.Line (-30, -30)-Step(Me.Width + 50, 0), QBColor(15)
  147.     Me.Line -Step(0, Me.Height + 40), QBColor(8)
  148.     Me.Line -Step(-(Me.Width + 50), 0), QBColor(8)
  149.     Me.Line -Step(0, -(Me.Height + 40)), QBColor(15)
  150.     Me.DrawWidth = nOldWidth
  151. End Sub
  152. ' =============================================================
  153. ' Name.........: GetNumDaysInMonth(nYear, nMonth)
  154. ' Description..: Computes the number of days in any given month
  155. ' Parameters...: <nYear>  - needed to check for leap years
  156. '                <nMonth> - the month number (1-12)
  157. ' Returns......: An integer representing the days in the month
  158. ' =============================================================
  159. Function GetNumDaysInMonth (nYear As Integer, nMonth As Integer) As Integer
  160.     Dim cMonth As String, nDays As Integer
  161.     cMonth = "312831303130313130313031"
  162.     ' Set defaults.
  163.     ' -------------
  164.     If nYear < 100 Or nYear > 9999 Then nYear = Year(Now)
  165.     If nMonth < 1 Or nMonth > 12 Then nMonth = Month(Now)
  166.     ' Set the number of days in the requested month.
  167.     ' ----------------------------------------------
  168.     nDays = Val(Mid$(cMonth, nMonth * 2 - 2 + 1, 2))
  169.     ' Compensate if requested year is a leap year, and month is February.
  170.     ' -------------------------------------------------------------------
  171.     If IsLeapYear(nYear) And nMonth = 2 Then nDays = nDays + 1
  172.     GetNumDaysInMonth = nDays
  173. End Function
  174. Sub gpMonthSpin_MouseDown (Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
  175.     gpMonthSpin(Index).PictureDnChange = 2
  176.     TmrMonthSpin.Interval = 500
  177.     TmrMonthSpin.Enabled = True
  178.     TmrMonthSpin.Tag = Choose(Index, -1, 1)
  179.     nCurrentMonth = nCurrentMonth + TmrMonthSpin.Tag
  180.     PrintMonthText
  181. End Sub
  182. Sub gpMonthSpin_MouseUp (Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
  183.     gpMonthSpin(Index).PictureDnChange = 0
  184.     ' turn off timer
  185.     TmrMonthSpin.Enabled = False
  186.     PrintMonth
  187. End Sub
  188. ' =============================================================
  189. ' Name.........: IsLeapYear( nYear )
  190. ' Description..:  Determines if a year is a leap year, or not.
  191. ' Parameters...: <nYear>  -
  192. ' Returns......: An integer (boolean). True = it is a leap year
  193. ' =============================================================
  194. Function IsLeapYear (nYear)
  195.    ' If the year is evenly divisible by 4 and not divisible
  196.    ' by 100, or if the year is evenly divisible by 400, then
  197.    ' it's a leap year.
  198.    IsLeapYear = (nYear Mod 4 = 0 And nYear Mod 100 <> 0) Or (nYear Mod 400 = 0)
  199. End Function
  200. Sub pic_Click ()
  201.     ' Return to 'sub-level' code.
  202.     ' ---------------------------
  203.     If nCurrentDay > 0 Then
  204.         gDate = DateSerial(nCurrentYear, nCurrentMonth, nCurrentDay)
  205.         Me.Hide
  206.     End If
  207. End Sub
  208. Sub pic_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single)
  209.     ' Just pass it along to "MouseMove".
  210.     ' ----------------------------------
  211.     pic_MouseMove Button, Shift, x, y
  212. End Sub
  213. Sub pic_MouseMove (Button As Integer, Shift As Integer, x As Single, y As Single)
  214.     Dim i  As Integer
  215.     Dim xt As Integer, x1 As Integer, x2 As Integer
  216.     Dim yt As Integer, y1 As Integer, y2 As Integer
  217.     ' OK. The mouse is moving over the picture. Do we care?
  218.     ' Only if the left mouse button is pressed.
  219.     ' We then need to find out which part of the picture,
  220.     ' the mouse is over, and change the shadow state.
  221.     If (Button = 1) Then
  222.         For i = 1 To 42
  223.             
  224.             yt = Int((i - 1) / 7) + 1
  225.             xt = i - (Int((yt - 1) * 7))
  226.             y1 = (yt - 1) * nBlockHeight: y2 = yt * nBlockHeight
  227.             x1 = (xt - 1) * (nWidth * 2): x2 = xt * (nWidth * 2)
  228.             If (x >= x1) And (x <= x2) And (y >= y1) And (y <= y2) Then nBlockNdx = i: Exit For
  229.         Next
  230.         If (nBlockNdx <> nCopyBlockNdx) And (nBlockNdx > 0) And (nBlockNdx - nStartDay <= nTotalDays) And (nBlockNdx - nStartDay > 0) Then
  231.             
  232.             PrintDay nCopyBlockNdx, 0, 0, 0
  233.             nCopyBlockNdx = nBlockNdx
  234.             nCurrentDay = nBlockNdx - nStartDay
  235.             PrintDay nCopyBlockNdx, 1, 0, 0
  236.             
  237.         End If
  238.     End If
  239. End Sub
  240. Sub pic_MouseUp (Button As Integer, Shift As Integer, x As Single, y As Single)
  241.     pic_Click
  242. End Sub
  243. ' ===============================================================
  244. ' Name.........: PrintDay( nDayIndex, lBorder, lBold, nCaption )
  245. ' Description..: Draws / Clears the border around a box
  246. ' Parameters...: <nDayIndex>  - Number of box to deal with (1-42)
  247. '                <lSetBorder> - True  = draw a 3D border
  248. '                               false = clear the border
  249. ' ===============================================================
  250. Sub PrintDay (nCurrBlock, lBorder As Integer, lBold As Integer, nCaption As Integer)
  251.     Dim x As Integer, x1 As Integer, x2 As Integer
  252.     Dim y As Integer, y1 As Integer, y2 As Integer
  253.     Dim cCaption As String
  254.     ReDim aBorderColours(4)
  255.         
  256.     ' Setup colours for border / no border.
  257.     ' -------------------------------------
  258.     If lBorder Then
  259.         aBorderColours(1) = 0
  260.         aBorderColours(2) = 15
  261.         aBorderColours(3) = 15
  262.         aBorderColours(4) = 0
  263.     Else
  264.         aBorderColours(1) = 7
  265.         aBorderColours(2) = 7
  266.         aBorderColours(3) = 7
  267.         aBorderColours(4) = 7
  268.     End If
  269.     y = Int((nCurrBlock - 1) / 7) + 1
  270.     x = nCurrBlock - (Int((y - 1) * 7))
  271.     y1 = (y - 1) * nBlockHeight: y2 = y * nBlockHeight
  272.     x1 = (x - 1) * (nWidth * 2): x2 = x * (nWidth * 2)
  273.         
  274.     pic.Line (x1, y1)-(x2, y1), QBColor(aBorderColours(1))
  275.     pic.Line (x2, y1)-(x2, y2), QBColor(aBorderColours(2))
  276.     pic.Line (x2, y2)-(x1, y2), QBColor(aBorderColours(3))
  277.     pic.Line (x1, y2)-(x1, y1), QBColor(aBorderColours(4))
  278.     ' Set Bold/Unbold attribute (only Bold if it's today)
  279.     ' and print caption (only if there is a caption to print!)
  280.     If nCaption > 0 Then
  281.             
  282.         pic.FontBold = False: pic.ForeColor = QBColor(0)
  283.         If lBold Then pic.FontBold = True: : pic.ForeColor = QBColor(4)
  284.         cCaption = CStr(nCaption)
  285.         pic.CurrentX = x1 + ((x2 - x1) - TextWidth(cCaption)) / 2
  286.         pic.CurrentY = y1 + ((y2 - y1) - TextHeight(cCaption)) / 2
  287.         pic.Print cCaption
  288.     End If
  289. End Sub
  290. ' =============================================================
  291. ' Name.........: PrintMonth()
  292. ' Description..: Output month text & numbers
  293. ' Notes........: This is a 'mega-slow' procedure. It's a pity
  294. '                we can't do without it.
  295. ' =============================================================
  296. Sub PrintMonth ()
  297.     Static nCopyYear As Integer  ' Saved, so we don't needlessly print the same
  298.     Static nCopyMonth As Integer ' month twice.
  299.     Dim nCount  As Integer
  300.     Dim nWeeks As Integer
  301.     Dim nCaption As Integer
  302.     If (nCurrentYear <> nCopyYear Or nCurrentMonth <> nCopyMonth) Then
  303.         pic.Visible = False
  304.         pic.Cls
  305.         nCopyYear = nCurrentYear: nCopyMonth = nCurrentMonth
  306.         
  307.         ' ======================================================
  308.         ' First day in a month.
  309.         ' An integer between 1 (Sunday) and 7 (Saturday)
  310.         ' that represents the day of the week for a date argument.
  311.         ' ======================================================
  312.         nStartDay = Weekday(DateSerial(nCurrentYear, nCurrentMonth, 1)) - 1
  313.         
  314.         ' ======================================================
  315.         ' Total days in a month.
  316.         ' An integer between 1 and ( 28 or 29 or 30 or 31 )
  317.         ' that represents the number of days in a month.
  318.         ' ======================================================
  319.         nTotalDays = GetNumDaysInMonth(nCurrentYear, nCurrentMonth)
  320.         ' ======================================================
  321.         ' Total weeks in a month.
  322.         ' An integer between 4 and 6
  323.         ' that represents the number of weeks in a month.
  324.         ' ======================================================
  325.         nWeeks = Int((nTotalDays + nStartDay) / 7) + Sgn((nTotalDays + nStartDay) Mod 7)
  326.         
  327.         ' ======================================================
  328.         ' Calculate vertical space needed to display the days
  329.         ' ======================================================
  330.         nBlockHeight = (pic.Height - 50) / nWeeks
  331.         PrintMonthText
  332.         ' ======================================================
  333.         ' Adjust 'Current Day' In case it's .GT. 'total days'
  334.         ' ======================================================
  335.         While nCurrentDay > nTotalDays: nCurrentDay = nCurrentDay - 1: Wend
  336.         nBlockNdx = nCurrentDay + nStartDay
  337.         nCopyBlockNdx = nBlockNdx
  338.         ' ==============================================
  339.         '  Output the month 'Captions'
  340.         ' ==============================================
  341.         For nCount = 1 To nWeeks * 7
  342.             
  343.             nCaption = IIf((nCount >= nStartDay + 1) And (nCount < nTotalDays + nStartDay + 1), nCount - nStartDay, 0)
  344.             
  345.             PrintDay nCount, 0, nCurrentYear = Year(Now) And nCurrentMonth = Month(Now) And nCount - nStartDay = Day(Now), nCaption
  346.         Next
  347.         ' ==============================================
  348.         ' Draw the border around selected day.
  349.         ' ==============================================
  350.         PrintDay nCurrentDay + nStartDay, 1, 0, 0
  351.         pic.Visible = True
  352.     End If
  353. End Sub
  354. ' =============================================================
  355. ' Name.........: PrintMonthText()
  356. ' Description..: Output month text
  357. ' =============================================================
  358. Sub PrintMonthText ()
  359.     If nCurrentMonth > 12 Then nCurrentMonth = 1: nCurrentYear = nCurrentYear + 1
  360.     If nCurrentMonth < 1 Then nCurrentMonth = 12: nCurrentYear = nCurrentYear - 1
  361.     nCurrentYear = IIf(nCurrentYear > 9999, 9999, nCurrentYear)
  362.     nCurrentYear = IIf(nCurrentYear < 100, 100, nCurrentYear)
  363.     lblMonthText.Caption = Format$(DateSerial(nCurrentYear, nCurrentMonth, 1), "mmmm yyyy")
  364.     Me.Refresh
  365. End Sub
  366. Sub TmrMonthSpin_Timer ()
  367.     ' Speed up the timer, on each call.
  368.     ' ---------------------------------
  369.     TmrMonthSpin.Interval = TmrMonthSpin.Interval * .8
  370.     ' Update the current month, and print text.
  371.     ' ----------------------------------------
  372.     nCurrentMonth = nCurrentMonth + TmrMonthSpin.Tag
  373.     PrintMonthText
  374. End Sub
  375.