Posted: Sun Jun 23, 2002 12:05 am
Restored from previous forum. Originally posted by Branston.
I'm an absolute beginner with PB. So, for any other beginners in this wonderful language, I hope this may be useful? I'm just starting out coding in PB and wanted to put something back into the community. It's a small program that tells the time and date in words. It's very silly. but I had fun writing it. It helped me understand a bit about the way PB works, so in turn I hope it might help you too.
;----------------------- programme start --------------------------------
; 'Funky time' written just for fun to learn this wonderful language.
;
; It needs library system2 for time and date functions.
; It WON'T work without it!
; Get this library from Mr Skunks website at http://www.skunknet.fr.st/
width=200 ; width of funky time display window
height=128 ; height of funky time display window
screen_height=getsystemmetrics_(#SM_CYSCREEN) ; get users screen settings
screen_width=getsystemmetrics_(#SM_CXSCREEN) ; get users screen settings
; so we can center funky time window
posx=(screen_width/2)-width/2 ; center up our window
posy=(screen_height/2)-height ; center up our window
Gosub getthetime:
OpenWindow(0,posx ,posy , 1, 1, #PB_Window_SystemMenu , "Funky Time")
While yyheight ; scroll funky time window open
Gosub Drawcircles:
Gosub dothewindow:
yy=yy+2
Delay(1)
ResizeWindow(width,yy)
Wend
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow ; Has the user pressed close button?
While height>2 ; Yes, so scroll funky time window down
height=height-2
Delay(1)
ResizeWindow(width,height)
Wend
Quit = 1 ; and signal a quit
EndIf
If eventID = #PB_EventRepaint ;repaint the funky time window?
Gosub Drawcircles:
Gosub dothewindow:
EndIf
Until Quit = 1 ; quit out!
End
;~~~~~~~~~~ Sub Routines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
getthetime:
GetTime() ; call to user library system2!! won't work without it!!!
;Get this library from Mr Skunks website at http://www.skunknet.fr.st/
year.l=Year()
month.l=Month()
day.l=Day()
dayweek.l=DayWeek()
hour.l=Hour()
minute.l=Minute()
second.l=Second()
day$=Str(day.l); work out day
Select dayweek.l
Case 0
dayweek$="Sunday"
Case 1
dayweek$="Monday"
Case 2
dayweek$="Tuesday"
Case 3
dayweek$="Wednesday"
Case 4
dayweek$="Thursday"
Case 5
dayweek$="Friday"
Case 6
dayweek$="Saturday"
EndSelect
;Work out month
Select month.l
Case 1
month$="January"
Case 2
month$="February"
Case 3
month$="March"
Case 4
month$="April"
Case 5
month$="May"
Case 6
month$="June"
Case 7
month$="July"
Case 8
month$="August"
Case 9
month$="September"
Case 10
month$="October"
Case 11
month$="November"
Case 12
month$="December"
EndSelect
;Work out correct suffix for day
If day.l >= 4 And day.l = 24 And day.l = 13 And hour.l = 59 ; well, almost exactly!
random$="EXACTLY!"
Gosub fixtime:
EndIf
If second.l > 1 And second.l 5 And second.l 10 And second.l 15 And second.l 20 And second.l 25 And second.l 30 And second.l 35 And second.l 40 And second.l 45 And second.l 50 And second.l 55 And second.l <= 58
random$="almost"
Gosub fixtime:
EndIf
If minute.l <= 9
minute$="0"+Str(minute.l)
Else
minute$=Str(minute.l)
EndIf
saytime$=" It's "+random$+" "+Str(hour.l)+":"+minute$+" "+ampm$+" "
sayday$=" "+dayweek$+", "+day$+suffix$+" "+month$+" "
Return
dothewindow:
StartDrawing(WindowOutput())
Box(0,35,200,45,RGB(0,0,0))
FrontColor(255,255,255)
BackColor(0,0,0)
Locate(15,40)
DrawText(saytime$)
Locate(15,60)
DrawText(sayday$)
StopDrawing()
Return
fixtime: ;adds a minute to actual time when the seconds are more than 30
If minute.l <= 58
minute.l = minute.l + 1
Else
minute.l = 0
If hour.l <= 23
hour.l = hour.l + 1
Else
hour.l = 0
EndIf
EndIf
Return
Drawcircles:
StartDrawing(WindowOutput())
For x = 0 To 100
boxx=Random(200)
boxy=Random(128)
r=Random(255)
g=Random(255)
b=Random(255)
size=5+Random(25)
Circle(boxx,boxy,size,RGB(r,g,b)) ; a nice random circle...
Next x
StopDrawing()
Return
Edited by - branston on 23 June 2002 01:06:55
I'm an absolute beginner with PB. So, for any other beginners in this wonderful language, I hope this may be useful? I'm just starting out coding in PB and wanted to put something back into the community. It's a small program that tells the time and date in words. It's very silly. but I had fun writing it. It helped me understand a bit about the way PB works, so in turn I hope it might help you too.

;----------------------- programme start --------------------------------
; 'Funky time' written just for fun to learn this wonderful language.
;
; It needs library system2 for time and date functions.
; It WON'T work without it!
; Get this library from Mr Skunks website at http://www.skunknet.fr.st/
width=200 ; width of funky time display window
height=128 ; height of funky time display window
screen_height=getsystemmetrics_(#SM_CYSCREEN) ; get users screen settings
screen_width=getsystemmetrics_(#SM_CXSCREEN) ; get users screen settings
; so we can center funky time window
posx=(screen_width/2)-width/2 ; center up our window
posy=(screen_height/2)-height ; center up our window
Gosub getthetime:
OpenWindow(0,posx ,posy , 1, 1, #PB_Window_SystemMenu , "Funky Time")
While yyheight ; scroll funky time window open
Gosub Drawcircles:
Gosub dothewindow:
yy=yy+2
Delay(1)
ResizeWindow(width,yy)
Wend
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow ; Has the user pressed close button?
While height>2 ; Yes, so scroll funky time window down
height=height-2
Delay(1)
ResizeWindow(width,height)
Wend
Quit = 1 ; and signal a quit
EndIf
If eventID = #PB_EventRepaint ;repaint the funky time window?
Gosub Drawcircles:
Gosub dothewindow:
EndIf
Until Quit = 1 ; quit out!
End
;~~~~~~~~~~ Sub Routines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
getthetime:
GetTime() ; call to user library system2!! won't work without it!!!
;Get this library from Mr Skunks website at http://www.skunknet.fr.st/
year.l=Year()
month.l=Month()
day.l=Day()
dayweek.l=DayWeek()
hour.l=Hour()
minute.l=Minute()
second.l=Second()
day$=Str(day.l); work out day
Select dayweek.l
Case 0
dayweek$="Sunday"
Case 1
dayweek$="Monday"
Case 2
dayweek$="Tuesday"
Case 3
dayweek$="Wednesday"
Case 4
dayweek$="Thursday"
Case 5
dayweek$="Friday"
Case 6
dayweek$="Saturday"
EndSelect
;Work out month
Select month.l
Case 1
month$="January"
Case 2
month$="February"
Case 3
month$="March"
Case 4
month$="April"
Case 5
month$="May"
Case 6
month$="June"
Case 7
month$="July"
Case 8
month$="August"
Case 9
month$="September"
Case 10
month$="October"
Case 11
month$="November"
Case 12
month$="December"
EndSelect
;Work out correct suffix for day
If day.l >= 4 And day.l = 24 And day.l = 13 And hour.l = 59 ; well, almost exactly!
random$="EXACTLY!"
Gosub fixtime:
EndIf
If second.l > 1 And second.l 5 And second.l 10 And second.l 15 And second.l 20 And second.l 25 And second.l 30 And second.l 35 And second.l 40 And second.l 45 And second.l 50 And second.l 55 And second.l <= 58
random$="almost"
Gosub fixtime:
EndIf
If minute.l <= 9
minute$="0"+Str(minute.l)
Else
minute$=Str(minute.l)
EndIf
saytime$=" It's "+random$+" "+Str(hour.l)+":"+minute$+" "+ampm$+" "
sayday$=" "+dayweek$+", "+day$+suffix$+" "+month$+" "
Return
dothewindow:
StartDrawing(WindowOutput())
Box(0,35,200,45,RGB(0,0,0))
FrontColor(255,255,255)
BackColor(0,0,0)
Locate(15,40)
DrawText(saytime$)
Locate(15,60)
DrawText(sayday$)
StopDrawing()
Return
fixtime: ;adds a minute to actual time when the seconds are more than 30
If minute.l <= 58
minute.l = minute.l + 1
Else
minute.l = 0
If hour.l <= 23
hour.l = hour.l + 1
Else
hour.l = 0
EndIf
EndIf
Return
Drawcircles:
StartDrawing(WindowOutput())
For x = 0 To 100
boxx=Random(200)
boxy=Random(128)
r=Random(255)
g=Random(255)
b=Random(255)
size=5+Random(25)
Circle(boxx,boxy,size,RGB(r,g,b)) ; a nice random circle...
Next x
StopDrawing()
Return
Edited by - branston on 23 June 2002 01:06:55