-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmDatePicker.frm
339 lines (272 loc) · 6.98 KB
/
frmDatePicker.frm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmDatePicker
ClientHeight = 5415
ClientLeft = 120
ClientTop = 465
ClientWidth = 5760
OleObjectBlob = "frmDatePicker.frx":0000
StartUpPosition = 2 'CenterScreen
End
Attribute VB_Name = "frmDatePicker"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Source: https://github.com/opi1101
Private mCancelled As Boolean
Private mDate As Double
Private Sub UserForm_Initialize()
Caption = ThisWorkbook.Name
fillMonths
fillDayNames
DateToUserForm DateTime.Date
End Sub
Property Get Cancelled() As Boolean
Cancelled = mCancelled
End Property
Property Get DateAsDouble() As Double
DateAsDouble = mDate
End Property
Property Get SelectedYear() As Integer
On Error Resume Next
SelectedYear = txtYear.Text
End Property
Property Get SelectedMonth() As Integer
On Error Resume Next
SelectedMonth = (cboMonth.ListIndex + 1)
End Property
Sub DateToUserForm(Dat As Double)
mDate = Dat
txtYear.Text = Year(Dat)
cboMonth.ListIndex = Month(Dat) - 1
updateCalendar Dat
End Sub
Private Sub lblNext_Click()
DateToUserForm DateSerial(SelectedYear, SelectedMonth + 1, 1)
End Sub
Private Sub lblPrev_Click()
DateToUserForm DateSerial(SelectedYear, SelectedMonth - 1, 1)
End Sub
Private Sub lblToday_Click()
DateToUserForm Date
End Sub
Private Sub lblTomorrow_Click()
DateToUserForm DateAdd("d", 1, Date)
End Sub
Private Sub lblYesterday_Click()
DateToUserForm DateAdd("d", -1, Date)
End Sub
Private Sub updateCalendar(ByVal Dat As Double)
Dim x As Byte, d As Byte, l As Byte, f As Byte
l = Day(DateSerial(Year(Dat), Month(Dat) + 1, 1) - 1) ' Last day
f = Weekday(DateSerial(Year(Dat), Month(Dat), 1), vbMonday) ' First weekday number
For x = 3 To 44 ' Labels
With Controls("Label" & x)
Select Case True
Case x - 2 < f, d >= l
.Visible = False
Case Else
d = d + 1
.Caption = d
.Visible = True
If d = Day(Dat) Then
selectDay Controls("Label" & x)
End If
End Select
End With
Next x
End Sub
Private Sub cboMonth_Change()
Dim b As Boolean
b = (cboMonth.ListIndex > -1)
frCalendar.Visible = b
If b = False Then
MsgBox "Invalid month provided: " & cboMonth.Text & vbNewLine & "Please select month from the dropdown list.", vbOKOnly, Caption
Exit Sub
End If
DateToUserForm DateSerial(SelectedYear, SelectedMonth, 1)
End Sub
Private Sub txtYear_Change()
Dim b As Boolean
If txtYear.TextLength <> 4 Then Exit Sub
b = (txtYear.Text Like "####")
frCalendar.Visible = b
If b = False Then
MsgBox "Invalid year provided: " & txtYear.Text & vbNewLine & "Please provide year in 'yyyy' format.", vbOKOnly, Caption
Exit Sub
End If
DateToUserForm DateSerial(SelectedYear, SelectedMonth, 1)
End Sub
Private Sub btnOk_Click()
Select Case True
Case (Not txtYear.Text Like "####")
MsgBox "Invalid year provided: " & txtYear.Text & vbNewLine & "Please provide year in 'yyyy' format.", vbOKOnly, Caption
Case (cboMonth.ListIndex = -1)
MsgBox "Invalid month provided: " & cboMonth.Text & vbNewLine & "Please select month from the dropdown list.", vbOKOnly, Caption
Case Else
Hide
End Select
End Sub
Private Sub fillMonths()
Dim x As Byte
With cboMonth
.Clear
For x = 1 To 12
.AddItem StrConv(MonthName(x), vbProperCase)
Next x
End With
End Sub
Private Sub fillDayNames()
lblMon = WeekdayName(1, True, vbMonday)
lblTue = WeekdayName(2, True, vbMonday)
lblWed = WeekdayName(3, True, vbMonday)
lblThu = WeekdayName(4, True, vbMonday)
lblFri = WeekdayName(5, True, vbMonday)
lblSat = WeekdayName(6, True, vbMonday)
lblSun = WeekdayName(7, True, vbMonday)
End Sub
Private Sub selectDay(Lbl As Object)
Dim x As Byte
mDate = DateSerial(SelectedYear, SelectedMonth, Int(Lbl.Caption))
For x = 3 To 44 ' Labels
With Controls("Label" & x)
.BackStyle = fmBackStyleTransparent
.ForeColor = &H8000000D
If .Name = Lbl.Name Then
.BackStyle = fmBackStyleOpaque
.ForeColor = vbWhite
End If
End With
Next x
End Sub
Private Sub Label10_Click()
selectDay Label10
End Sub
Private Sub Label11_Click()
selectDay Label11
End Sub
Private Sub Label12_Click()
selectDay Label12
End Sub
Private Sub Label13_Click()
selectDay Label13
End Sub
Private Sub Label14_Click()
selectDay Label14
End Sub
Private Sub Label15_Click()
selectDay Label15
End Sub
Private Sub Label16_Click()
selectDay Label16
End Sub
Private Sub Label17_Click()
selectDay Label17
End Sub
Private Sub Label18_Click()
selectDay Label18
End Sub
Private Sub Label19_Click()
selectDay Label19
End Sub
Private Sub Label20_Click()
selectDay Label20
End Sub
Private Sub Label21_Click()
selectDay Label21
End Sub
Private Sub Label22_Click()
selectDay Label22
End Sub
Private Sub Label23_Click()
selectDay Label23
End Sub
Private Sub Label24_Click()
selectDay Label24
End Sub
Private Sub Label25_Click()
selectDay Label25
End Sub
Private Sub Label26_Click()
selectDay Label26
End Sub
Private Sub Label27_Click()
selectDay Label27
End Sub
Private Sub Label28_Click()
selectDay Label28
End Sub
Private Sub Label29_Click()
selectDay Label29
End Sub
Private Sub Label3_Click()
selectDay Label3
End Sub
Private Sub Label30_Click()
selectDay Label30
End Sub
Private Sub Label31_Click()
selectDay Label31
End Sub
Private Sub Label32_Click()
selectDay Label32
End Sub
Private Sub Label33_Click()
selectDay Label33
End Sub
Private Sub Label34_Click()
selectDay Label34
End Sub
Private Sub Label35_Click()
selectDay Label35
End Sub
Private Sub Label36_Click()
selectDay Label36
End Sub
Private Sub Label37_Click()
selectDay Label37
End Sub
Private Sub Label38_Click()
selectDay Label38
End Sub
Private Sub Label39_Click()
selectDay Label39
End Sub
Private Sub Label4_Click()
selectDay Label4
End Sub
Private Sub Label40_Click()
selectDay Label40
End Sub
Private Sub Label41_Click()
selectDay Label41
End Sub
Private Sub Label42_Click()
selectDay Label42
End Sub
Private Sub Label43_Click()
selectDay Label43
End Sub
Private Sub Label44_Click()
selectDay Label44
End Sub
Private Sub Label5_Click()
selectDay Label5
End Sub
Private Sub Label6_Click()
selectDay Label6
End Sub
Private Sub Label7_Click()
selectDay Label7
End Sub
Private Sub Label8_Click()
selectDay Label8
End Sub
Private Sub Label9_Click()
selectDay Label9
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Cancel = True
mCancelled = (CloseMode <> VbQueryClose.vbFormCode)
Hide
End Sub