I wrote this calendar in VB early this year ....
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1651&stc=1&d=117946954 4">
<hr/>
Portion of code for generating the dates in ea month (2000 - 2100)
*Definitely not directly applicable to PBP, there's lot of work needed to port it. Be great if PBP supported strings & string manipulation !Code:Public Sub Draw_Calendar() '----------------------------------------------------------------------------- '// Build / draw calendar onto field where user can actively select from it '----------------------------------------------------------------------------- Dim Print_Y As Integer 'Contains current X-axis for printing Dim Print_X As Integer 'Y-axis Dim Date_Num As String 'Holds current day for the selected month Dim Cal_Col As Integer 'Column in (6x7) matrix Dim Cal_Row As Integer 'Row Dim Days_From_01 As Long 'Total days from the year 0001 Dim Start_Day As Long 'First day of the month Dim i As Long 'General working var ReDim Grid_Dat(6, 7) 'Grid contents (all the dates in the month) '// From Jan 0001 to 2000 there's 730127 days (Crucial needed key to this algorithm) Days_From_01 = 730127 '// Wipe area ready for new print / render Calendar_Field.Cls If Draw_3D_Cells.Checked Then Blit_3D_Cells End If Days_In_Months(2) = 28 'Assume no leap '// Check for leap year with currently selected year If Is_Leap_Year(Set_Year) Then Days_In_Months(2) = 29 '// Add up total days from yr 2000 until selected yr For i = 2000 To Set_Year - 1 Days_In_Year = 365 'No leap '// Check for leap If Is_Leap_Year(i) Then Days_In_Year = 366 'Leap End If '// Sum it all Days_From_01 = Days_From_01 + Days_In_Year Next i '// Add up total days until a month before the selected month For i = 1 To (Set_Month - 1) Days_From_01 = Days_From_01 + Days_In_Months(i) Next i '// Swap vars (new meaninful name with what we're about to do next) Start_Day = Days_From_01 '// Dec week until we find the start day of the month Do While Start_Day > 7: Start_Day = Start_Day - 7: Loop '// Reset to 0 if > 7 Start_Day = Start_Day Mod 7 '// Starting print coords Print_X = (Start_Day * 23) + 5 Print_Y = 5 '// Starting col in sync with the actual first day of the month Cal_Col = Start_Day '// Loop through days in month (1 to total) ' For i = 1 To Days_In_Months(Set_Month) '// Set new row after 7 across (gird is 6x7) If Print_X > 160 Then ' Print_Y = Print_Y + 23 'Inc Print_X = 5 'Reset Cal_Row = Cal_Row + 1 'Inc Cal_Col = 0 'Reset End If '// Copy var to string Date_Num = Trim(Str(i)) '// Add space for single digit vals (center alignment) If Len(Date_Num) = 1 Then Date_Num = Space(1) & Date_Num End If '// Print date to feild using the TextOut API (much faster) TextOut Calendar_Field.hdc, Print_X, Print_Y, Date_Num, Len(Date_Num) '// Store locations in grid array for later usage (user clicks fields) Grid_Dat(Cal_Row, Cal_Col) = Date_Num '// Inc X-axis for printing and col pos Print_X = Print_X + 23 Cal_Col = Cal_Col + 1 Next Start_Day = Start_Day + Set_Day 'Set start day in month Cal_Col = 0 'Reset col & row Cal_Row = 0 ' '----------------------------------------------------------------------------- '// Here we need to locate the col & row in the grid that matches first day '----------------------------------------------------------------------------- For i = 0 To Start_Day - 1 'Loop through Cal_Col = Cal_Col + 1 'Inc col If Cal_Col = 7 Then 'New row? Cal_Row = Cal_Row + 1 'Inc row Cal_Col = 0 'Reset col End If Next If Show_3D_Sel.Checked Then '// Blit selected 3D cell BitBlt Calendar_Field.hdc, Cal_Col * 23 + 3, Cal_Row * 23 + 3, 20, 20, Selected_3D.hdc, 0, 0, SrcCopy '// Rectangle around it Rectangle Calendar_Field.hdc, Cal_Col * 23 + 3, Cal_Row * 23 + 3, 23 + Cal_Col * 23, 23 + Cal_Row * 23 '// Show day inside cell TextOut Calendar_Field.hdc, Cal_Col * 23 + 5, Cal_Row * 23 + 5, Grid_Dat(Cal_Row, Cal_Col), Len(Grid_Dat(Cal_Row, Cal_Col)) '// Else '(Show 2D selector) '// '// Position selector square to selected day in the month Selector.Move (Cal_Col * 23) + 5, (Cal_Row * 23) + 5 '// Show date inside square Selector.Cls TextOut Selector.hdc, 1, 0, Grid_Dat(Cal_Row, Cal_Col), Len(Grid_Dat(Cal_Row, Cal_Col)) End If '// Build return string (mm-dd-yy) Return_Date = Set_Month & "-" & Grid_Dat(Cal_Row, Cal_Col) & "-" & Set_Year Call Extract_Date_Specifics '// Update bottom portion of picker with a readout of the selected date Show_Date.Caption = Format(Return_Date, IIf(Show_Long_Date.Checked, "dddd, mmmm d, yyyy", "dd/mm/yyyy")) '// Reset (var only used by Set_Picker_Date proc to force a sel) Set_Day = 0 '// Draw grid? (optional) If Show_Grid.Checked Then Draw_Grid End If Calendar_Field.Refresh End Sub
<br/>




Bookmarks