forked from the-tech-academy/office_hours
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofficeHours.sb
444 lines (415 loc) · 11 KB
/
officeHours.sb
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
frmMain()
centerScreen()
Sub centerScreen
' This will get the user's system screen width & height divided by 2
' and subtract it from the Form's width & height dived by 2
' to center the form on app load
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
dw = Desktop.Width
dh = Desktop.Height
GraphicsWindow.Left = (dw / 2) - (gw / 2)
GraphicsWindow.Top = (dh / 2) - (gh / 2)
EndSub
' Build Frame
Sub frmMain
GraphicsWindow.CanResize = 0
GraphicsWindow.Width = 400
GraphicsWindow.Height = 350
GraphicsWindow.Title = "Office Hours"
GraphicsWindow.BackgroundColor = GraphicsWindow.GetColorFromRGB(240, 240, 240)
GraphicsWindow.FontBold = "False"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.Show()
' Enable the listener for Button Events
Controls.ButtonClicked = buttonClicked
' Buttons:
closeButton = Controls.AddButton("Close",290,290)
Controls.SetSize(closeButton,100,50)
' Labels & textBoxes:
GraphicsWindow.BrushColor = "black"
GraphicsWindow.FillRectangle(10,70,380,50)
GraphicsWindow.BrushColor = "#c9fffb"
GraphicsWindow.FillRectangle(11,71,378,48)
centerText()
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontBold = "True"
GraphicsWindow.DrawBoundText(10,30,100, "Current Time:")
GraphicsWindow.FontBold = "False"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontBold = "True"
GraphicsWindow.DrawBoundText(10,150,130, "Portland Office:")
GraphicsWindow.FontBold = "False"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontBold = "True"
GraphicsWindow.DrawBoundText(10,200,130, "New York Office:")
GraphicsWindow.FontBold = "False"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontBold = "True"
GraphicsWindow.DrawBoundText(10,250,130, "London Office:")
GraphicsWindow.FontBold = "False"
GraphicsWindow.BrushColor = "darkblue"
GraphicsWindow.FontBold = "True"
GraphicsWindow.DrawBoundText(300,30,100, "17:28:32 PST")
GraphicsWindow.FontBold = "False"
port_hour = Clock.Hour
port_min = Clock.Minute
GraphicsWindow.FontBold = "True"
getPortTime()
GraphicsWindow.DrawBoundText(150,150,250, port_time + " " + port_amPm + " - The Oregon branch is " + port_open + ".")
getNyTime()
GraphicsWindow.DrawBoundText(150,200,250, ny_time + " " + ny_amPm + " - The NY City branch is " + ny_open + ".")
getLonTime()
GraphicsWindow.DrawBoundText(150,250,250, lon_time + " " + lon_amPm + " - The London branch is " + lon_open + ".")
GraphicsWindow.FontBold = "False"
GraphicsWindow.BrushColor = "black"
EndSub
Sub centerText
' Character return + Line-feed
CR = Text.GetCharacter(13) + Text.GetCharacter(10)
'GraphicsWindow.FontName = "Tahoma"
'GraphicsWindow.FontSize = 12
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontBold = "True"
text1 = "All office hours are from:"
text2 = "9:00 am to 9:00 pm, or (0900) to (2100)."
'Text.GetLength(caption) means the number of characters in the caption. Default font size (height) is
'12 pixels and gross average width of the default font (Tahoma) assumed to be 7 pixels
'in this program. If the window width is gw, centering x position of the caption will be as follows.
wCaption1 = (Text.GetLength(text1) + 2) * 12 * .4
wCaption2 = (Text.GetLength(text2) + 2) * 12 * .48
x1 = Math.Floor((378 - wCaption1) / 2)
x2 = Math.Floor((378 - wCaption2) / 2)
GraphicsWindow.DrawBoundText(x1,75,378, text1)
GraphicsWindow.DrawBoundText(x2,100,378, text2)
'Or, if you use "Courier New" font, the font width is 0.6 times the font height. So, if the font size (height)
'is 12, you can calculate caption width as follows.
' wCaption = (Text.GetLength(caption) + 2) * 12 * 0.6
EndSub
' Define the Event functions
Sub buttonClicked
lastButton = Controls.LastClickedButton
If lastButton = closeButton Then
Program.End()
EndIf
EndSub
Sub getPortTime
If port_hour = 1 Then
port_time = 1
port_amPm = "Am"
port_open = "false"
ElseIf port_hour = 2 Then
port_time = 2
port_amPm = "Am"
port_open = "false"
ElseIf port_hour = 3 Then
port_time = 3
port_amPm = "Am"
port_open = "false"
ElseIf port_hour = 4 Then
port_time = 4
port_amPm = "Am"
port_open = "false"
ElseIf port_hour = 5 Then
port_time = 5
port_amPm = "Am"
port_open = "false"
ElseIf port_hour = 6 Then
port_time = 6
port_amPm = "Am"
port_open = "false"
ElseIf port_hour = 7 Then
port_time = 7
port_amPm = "Am"
port_open = "false"
ElseIf port_hour = 8 Then
port_time = 8
port_amPm = "Am"
port_open = "false"
ElseIf port_hour = 9 Then
port_time = 9
port_amPm = "Am"
port_open = "true"
ElseIf port_hour = 10 Then
port_time = 10
port_amPm = "Am"
port_open = "true"
ElseIf port_hour = 11 Then
port_time = 11
port_amPm = "Am"
port_open = "true"
ElseIf port_hour = 12 Then
port_time = 12
port_amPm = "Pm"
port_open = "true"
ElseIf port_hour = 13 Then
port_time = 1
port_amPm = "Pm"
port_open = "true"
ElseIf port_hour = 14 Then
port_time = 2
port_amPm = "Pm"
port_open = "true"
ElseIf port_hour = 15 Then
port_time = 3
port_amPm = "Pm"
port_open = "true"
ElseIf port_hour = 16 Then
port_time = 4
port_amPm = "Pm"
port_open = "true"
ElseIf port_hour = 17 Then
port_time = 5
port_amPm = "Pm"
port_open = "true"
ElseIf port_hour = 18 Then
port_time = 6
port_amPm = "Pm"
port_open = "true"
ElseIf port_hour = 19 Then
port_time = 7
port_amPm = "Pm"
port_open = "true"
ElseIf port_hour = 20 Then
port_time = 8
port_amPm = "Pm"
port_open = "true"
ElseIf port_hour = 21 Then
port_time = 9
port_amPm = "Pm"
port_open = "false"
ElseIf port_hour = 22 Then
port_time = 10
port_amPm = "Pm"
port_open = "false"
ElseIf port_hour = 23 Then
port_time = 11
port_amPm = "Pm"
port_open = "false"
ElseIf port_hour = 0 Then
port_time = 12
port_amPm = "Am"
port_open = "false"
EndIf
If port_open = "true" Then
port_open = "Open"
GraphicsWindow.BrushColor = "green"
Else
port_open = "Closed"
GraphicsWindow.BrushColor = "red"
EndIf
EndSub
Sub getNyTime
ny_hour = port_hour + 3
If ny_hour = 1 Then
ny_time = 1
ny_amPm = "Am"
ny_open = "false"
ElseIf ny_hour = 2 Then
ny_time = 2
ny_amPm = "Am"
ny_open = "false"
ElseIf ny_hour = 3 Then
ny_time = 3
ny_amPm = "Am"
ny_open = "false"
ElseIf ny_hour = 4 Then
ny_time = 4
ny_amPm = "Am"
ny_open = "false"
ElseIf ny_hour = 5 Then
ny_time = 5
ny_amPm = "Am"
ny_open = "false"
ElseIf ny_hour = 6 Then
ny_time = 6
ny_amPm = "Am"
ny_open = "false"
ElseIf ny_hour = 7 Then
ny_time = 7
ny_amPm = "Am"
ny_open = "false"
ElseIf ny_hour = 8 Then
ny_time = 8
ny_amPm = "Am"
ny_open = "false"
ElseIf ny_hour = 9 Then
ny_time = 9
ny_amPm = "Am"
ny_open = "true"
ElseIf ny_hour = 10 Then
ny_time = 10
ny_amPm = "Am"
ny_open = "true"
ElseIf ny_hour = 11 Then
ny_time = 11
ny_amPm = "Am"
ny_open = "true"
ElseIf ny_hour = 12 Then
ny_time = 12
ny_amPm = "Pm"
ny_open = "true"
ElseIf ny_hour = 13 Then
ny_time = 1
ny_amPm = "Pm"
ny_open = "true"
ElseIf ny_hour = 14 Then
ny_time = 2
ny_amPm = "Pm"
ny_open = "true"
ElseIf ny_hour = 15 Then
ny_time = 3
ny_amPm = "Pm"
ny_open = "true"
ElseIf ny_hour = 16 Then
ny_time = 4
ny_amPm = "Pm"
ny_open = "true"
ElseIf ny_hour = 17 Then
ny_time = 5
ny_amPm = "Pm"
ny_open = "true"
ElseIf ny_hour = 18 Then
ny_time = 6
ny_amPm = "Pm"
ny_open = "true"
ElseIf ny_hour = 19 Then
ny_time = 7
ny_amPm = "Pm"
ny_open = "true"
ElseIf ny_hour = 20 Then
ny_time = 8
ny_amPm = "Pm"
ny_open = "true"
ElseIf ny_hour = 21 Then
ny_time = 9
ny_amPm = "Pm"
ny_open = "false"
ElseIf ny_hour = 22 Then
ny_time = 10
ny_amPm = "Pm"
ny_open = "false"
ElseIf ny_hour = 23 Then
ny_time = 11
ny_amPm = "Pm"
ny_open = "false"
ElseIf ny_hour = 0 Then
ny_time = 12
ny_amPm = "Am"
ny_open = "false"
EndIf
If ny_open = "true" Then
ny_open = "Open"
GraphicsWindow.BrushColor = "green"
Else
ny_open = "Closed"
GraphicsWindow.BrushColor = "red"
EndIf
EndSub
Sub getLonTime
lon_hour = port_hour + 8
If lon_hour = 1 Then
lon_time = 1
lon_amPm = "Am"
lon_open = "false"
ElseIf lon_hour = 2 Then
lon_time = 2
lon_amPm = "Am"
lon_open = "false"
ElseIf lon_hour = 3 Then
lon_time = 3
lon_amPm = "Am"
lon_open = "false"
ElseIf lon_hour = 4 Then
lon_time = 4
lon_amPm = "Am"
lon_open = "false"
ElseIf lon_hour = 5 Then
lon_time = 5
lon_amPm = "Am"
lon_open = "false"
ElseIf lon_hour = 6 Then
lon_time = 6
lon_amPm = "Am"
lon_open = "false"
ElseIf lon_hour = 7 Then
lon_time = 7
lon_amPm = "Am"
lon_open = "false"
ElseIf lon_hour = 8 Then
lon_time = 8
lon_amPm = "Am"
lon_open = "false"
ElseIf lon_hour = 9 Then
lon_time = 9
lon_amPm = "Am"
lon_open = "true"
ElseIf lon_hour = 10 Then
lon_time = 10
lon_amPm = "Am"
lon_open = "true"
ElseIf lon_hour = 11 Then
lon_time = 11
lon_amPm = "Am"
lon_open = "true"
ElseIf lon_hour = 12 Then
lon_time = 12
lon_amPm = "Pm"
lon_open = "true"
ElseIf lon_hour = 13 Then
lon_time = 1
lon_amPm = "Pm"
lon_open = "true"
ElseIf lon_hour = 14 Then
lon_time = 2
lon_amPm = "Pm"
lon_open = "true"
ElseIf lon_hour = 15 Then
lon_time = 3
lon_amPm = "Pm"
lon_open = "true"
ElseIf lon_hour = 16 Then
lon_time = 4
lon_amPm = "Pm"
lon_open = "true"
ElseIf lon_hour = 17 Then
lon_time = 5
lon_amPm = "Pm"
lon_open = "true"
ElseIf lon_hour = 18 Then
lon_time = 6
lon_amPm = "Pm"
lon_open = "true"
ElseIf lon_hour = 19 Then
lon_time = 7
lon_amPm = "Pm"
lon_open = "true"
ElseIf lon_hour = 20 Then
lon_time = 8
lon_amPm = "Pm"
lon_open = "true"
ElseIf lon_hour = 21 Then
lon_time = 9
lon_amPm = "Pm"
lon_open = "false"
ElseIf lon_hour = 22 Then
lon_time = 10
lon_amPm = "Pm"
lon_open = "false"
ElseIf lon_hour = 23 Then
lon_time = 11
lon_amPm = "Pm"
lon_open = "false"
ElseIf lon_hour = 0 Then
lon_time = 12
lon_amPm = "Am"
lon_open = "false"
EndIf
If lon_open = "true" Then
lon_open = "Open"
GraphicsWindow.BrushColor = "green"
Else
lon_open = "Closed"
GraphicsWindow.BrushColor = "red"
EndIf
EndSub