|
Post by jarych on Jun 25, 2019 10:52:41 GMT
A very simple desktop timer program, for count-down and then upon reaching 0, plays an alert sound. The program is not immune yet to mistakes of user input, but the program works. BAS and a few other files are included attached.
(code also included here)
'------- 'Refer to desktop_timer_v09 from version 0.9 of june 16 12:30AM 2019 'This edition is demonstration edition to be called 'desktop_timer_demo_v09
vrshn$="demo v 0.9" flagVersion=0
dim pickalert$(12) 'which audio alert pickalert$(1)="bounce1.wav" pickalert$(2)="ringout.wav" aud$="bounce1.wav" dim alerttime$(4) 'which audio alert time in seconds alerttime$(1)="15" alerttime$(2)="30" alerttime$(3)="45" alerttime$(4)="60" audtime$="30"
nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "minutes part", 30, 66, 144, 20 statictext #main.statictext2, "seconds part", 198, 66, 144, 20 textbox #main.textbox3, 22, 96, 100, 25 textbox #main.textbox4, 190, 96, 100, 25 button #main.button5, "BEGIN", [button5Click], UL, 358, 96, 122, 25 button #main.button7,"STOP ALARM",[stopalarm],UL, 358, 156, 122, 25 statictext #main.statictext6, "MMM:SS", 358, 46, 144, 20 statictext #main.opts,"Options: Sound, Seconds of Sound",22,156,230,20 combobox #main.pickalert, pickalert$(),[picksound],22,190,100,25 combobox #main.pickalerttime, alerttime$(),[picksoundtime],140,190,100,25 button #main.about, "About",[about],UL,22,20,50,20 open "TIMER for your desktop" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10" print #main.statictext6,"!font sans_serif 14"
wait
[quit.main] flagVersion=0 Close #main END
[button5Click] 'Perform action for the button named 'button5' 'Insert your own code here flagready=0 'oneminalert=32 'not sure if the best place, alert to timer end is this many seconds oneminalert=val(audtime$) print #main.textbox3,"!contents? M$" print #main.textbox4,"!contents? S$" totaltimeseconds=val(M$)*60+val(S$)
notice ""+chr$(13)+str$(totaltimeseconds)+" total seconds" if totaltimeseconds>0 then flagready=1
timer 1000, [retimeQ] [retimeQ] SCAN totaltimeseconds=totaltimeseconds-1 if totaltimeseconds>=60 then M=int(totaltimeseconds/60) S=totaltimeseconds-60*M else M=0 S=totaltimeseconds end if T$=str$(M)+":"+str$(S) IF totaltimeseconds<=0 then timer 0
PRINT #main.statictext6,T$
if flagready=1 and totaltimeseconds=0 then timer 2000,[audioalert] [audioalert] 'playwave "beep.wav",loop playwave aud$,loop oneminalert=oneminalert-2 if oneminalert<=0 then playwave "" timer 0 flagready=0 end if end if
wait
[stopalarm] 'empty until development time playwave "" flagready=0 'oneminalert=32 oneminalert=val(audtime$) timer 0 REM may allow other inputs to remain REM this only stops timer, alert sound, and changes to countdown display. REM not a pause wait
[picksound] print #main.pickalert, "contents? aud$" wait
[picksoundtime] print #main.pickalerttime, "contents? audtime$" wait
[about] flagVersion=1 notice""+chr$ _ +"desktop timer "+vrshn$+" - very simple timer" _ +chr$(13)+chr$(13) _ +"Now usable but this is demonstration edition." _ +"(c) 2019, jarych" _ +chr$(13)+chr$(13) _ +"Choose mixed minutes & seconds to countdown. " _ +"Left-click 'BEGIN' button. " _ +"If you want to stop the alert sound early then" _ +chr$(13)+"left-click the 'STOP' button." _ +chr$(13)+"Simple choices allowed for alert sound and how long " _ +chr$(13)+"(in seconds) the alert will sound." _ +chr$(13)+chr$(13) _ +"Options are not kept between timer desktop sessions." wait
EDIT: link removed. See post further down for updated version package.)
|
|
|
Post by jarych on Jun 28, 2019 9:12:49 GMT
(EDIT: see most recent post for updated download link.) This one is better, being resistant to user input mistakes. The downloadable zipped package is for JB users who are interested in trying the program. The code will be found in the BAS file. (unless someone says he wants to see the code here in the post). The code for members who want to see it (took some effort and time to find package and reextract onto machine which does not have JB installed): The download link at bottom of message post --------- 'desktop timer, the name of program and project
'started June 14, 2019
'removing development commentaries for the demonstration package
'desktop_timer_v096
vrshn$=" 0.96"
flagVersion=0
invalidchar$="abcdefghijlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,.?/"
needcharacters$="1234567890" 'put in evening june 27, 2019
dim pickalert$(12) 'which audio alert
'pickalert$(1)="bounce1.wav"
'pickalert$(2)="ringout.wav"
aud$="sounds\bounce1.wav"
dim audname$(12)
gosub [fillsoundelements]
gosub [soundfilenamesonly]
dim alerttime$(5) 'which audio alert time in seconds
alerttime$(1)="15"
alerttime$(2)="30"
alerttime$(3)="45"
alerttime$(4)="60"
alerttime$(5)="75"
audtime$="30"
nomainwin
WindowWidth = 550
WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "minutes part", 30, 66, 144, 20
statictext #main.statictext2, "seconds part", 198, 66, 144, 20
textbox #main.textbox3, 22, 96, 100, 25
textbox #main.textbox4, 190, 96, 100, 25
button #main.button5, "BEGIN", [button5Click], UL, 358, 96, 122, 25
button #main.button7,"STOP ALARM",[stopalarm],UL, 358, 156, 122, 25
statictext #main.statictext6, "MMM:SS", 358, 46, 144, 20
statictext #main.opts,"Options: Sound, Seconds of Sound",22,156,230,20
'combobox #main.pickalert, pickalert$(),[picksound],22,190,100,25
combobox #main.pickalert,audname$(),[picksound],22,190,120,25
combobox #main.pickalerttime, alerttime$(),[picksoundtime],150,190,100,25
button #main.about, "About",[about],UL,22,20,50,20
open "TIMER for your desktop" for window as #main
print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
print #main.statictext6,"!font sans_serif 14"
wait
[quit.main]
flagVersion=0
Close #main
END
[button5Click] 'Perform action for the button named 'button5'
'Insert your own code here
flagready=0
'oneminalert=32 'not sure if the best place, alert to timer end is this many seconds
oneminalert=val(audtime$)
print #main.textbox3,"!contents? M$"
print #main.textbox4,"!contents? S$"
REM check if M$ and S$ inputs are good or bad
gosub [checktimeinputs]
IF flaginputscheck=0 then
NOTICE ""+chr$(13)+"Fix bad or missing time inputs values."
WAIT
END IF
totaltimeseconds=val(M$)*60+val(S$)
notice ""+chr$(13)+str$(totaltimeseconds)+" total seconds"
if totaltimeseconds>0 then flagready=1
timer 1000, [retimeQ]
[retimeQ]
SCAN
totaltimeseconds=totaltimeseconds-1
if totaltimeseconds>=60 then
M=int(totaltimeseconds/60)
S=totaltimeseconds-60*M
else
M=0
S=totaltimeseconds
end if
T$=str$(M)+":"+str$(S)
IF totaltimeseconds<=0 then timer 0
PRINT #main.statictext6,T$
if flagready=1 and totaltimeseconds=0 then
timer 2000,[audioalert]
[audioalert]
'playwave "beep.wav",loop
playwave aud$,loop
oneminalert=oneminalert-2
if oneminalert<=0 then
playwave ""
timer 0
flagready=0
end if
end if
wait
[stopalarm]
'empty until development time
playwave ""
flagready=0
'oneminalert=32
oneminalert=val(audtime$)
timer 0
REM may allow other inputs to remain
REM this only stops timer, alert sound, and changes to countdown display.
REM not a pause
wait
[picksound]
'print #main.pickalert, "contents? aud$"
print #main.pickalert, "selectionindex? v"
let aud$="sounds\"+audname$(v)
wait
[picksoundtime]
print #main.pickalerttime, "contents? audtime$"
wait
[about]
flagVersion=1
notice""+chr$ _
+"desktop timer v "+vrshn$+" - very simple timer" _
+chr$(13)+chr$(13) _
+"" _
+"(c) copyright 2019, jarych" _
+chr$(13)+chr$(13) _
+"Choose mixed minutes & seconds to countdown. " _
+"Left-click 'BEGIN' button. " _
+"If you want to stop the alert sound early then" _
+chr$(13)+"left-click the 'STOP' button." _
+chr$(13)+"A few choices are allowed for alert sound and how long " _
+chr$(13)+"(in seconds) the alert will sound."
wait
'----------------------------------SUBROUTINES-----------------------------
[fillsoundelements]
REM only nine elements this version
pickalert$(1)="sounds\bounce1.wav"
pickalert$(2)="sounds\ringout.wav"
pickalert$(3)="sounds\alarmbuzzer.wav"
pickalert$(4)="sounds\analog-watch.wav"
pickalert$(5)="sounds\CuckooClock.wav"
pickalert$(6)="sounds\low-train-horn.wav"
pickalert$(7)="sounds\old-fashioned-school-bell.wav"
pickalert$(8)="sounds\PageBeeps.wav"
pickalert$(9)="sounds\tolling-bell.wav"
return
[soundfilenamesonly]
REM for easier to read combobox sound selection
REM only show file name without directory path
for a=1 to 9
audname$(a)=mid$(pickalert$(a),8)
next a
'for a0=1 to 9
'print audname$(a0)
'next a0
return
[checktimeinputs] 'this routine is not working.
flaginputscheck=1 'assuming good inputs
if len(M$)=0 and len(S$)=0 then
flaginputscheck=0
goto [jumpout]
end if
if M$="0" or M$="" then
M$="0"
end if
if int(val(M$))<>val(M$) OR int(val(S$))<>val(S$) then
flaginputscheck=0
goto [jumpout]
end if
if val(S$)>60 then
notice ""+chr$+"Use mixed time units Minutes count and Seconds count, and ensure seconds as whole value from 0 to 59."
flaginputscheck=0
end if
if val(M$)>=1 and val(S$)>=60 then
notice ""+chr$(13)+"Such improper mixed units not allowed"
flaginputscheck=0
end if
'---------------------------------------------------this section put in on june 27, 2019 EVENING
REM want to try instr() to look for position of any bad input characters and set flag to 0
REM instr(referencestring,inputstring,placetostart)
for i0=1 to len(M$)
if instr(needcharacters$,mid$(M$,i0,1))=0 then
flaginputscheck=0
end if
next i0
for i1=1 to len(S$)
if instr(needcharacters$,mid$(S$,i1,1))=0 then
flaginputscheck=0
end if
next i1
'------------------------------------------------------------------
[jumpout]
rem decision on action for validity should occur in the button's branch.
return
|
|
|
Post by B+ on Jun 28, 2019 13:21:22 GMT
This one is better, being resistant to user input mistakes. The downloadable zipped package is for JB users who are interested in trying the program. The code will be found in the BAS file. (unless someone says he wants to see the code here in the post). Download at this link: download desktop_timer_demo_v096.zip, 11MBI would like to see the bas code, it can't be that much more than 1K versus 11MB? For my alarm clock (we just ran this exercise at another Basic forum) I used hh:mm (hours 0-23) format to compare directly to first 5 characters of TIME$ with no checks because I am only one who uses it and seeing the format is enough of a prompt for an INPUT string$. And for a Timer, I just INPUT minutes that accept fractions to compare with TIME$("ms" or "seconds") depending on if I checking a code time or an event time for myself. Mostly I am interested in your choice of checking input as we discussed elsewhere or you could just say... Thanks
|
|
|
Post by jarych on Jun 28, 2019 17:06:53 GMT
This one is better, being resistant to user input mistakes. The downloadable zipped package is for JB users who are interested in trying the program. The code will be found in the BAS file. (unless someone says he wants to see the code here in the post). Download at this link: download desktop_timer_demo_v096.zip, 11MBI would like to see the bas code, it can't be that much more than 1K versus 11MB? For my alarm clock (we just ran this exercise at another Basic forum) I used hh:mm (hours 0-23) format to compare directly to first 5 characters of TIME$ with no checks because I am only one who uses it and seeing the format is enough of a prompt for an INPUT string$. And for a Timer, I just INPUT minutes that accept fractions to compare with TIME$("ms" or "seconds") depending on if I checking a code time or an event time for myself. Mostly I am interested in your choice of checking input as we discussed elsewhere or you could just say... Thanks That is the messy part of the code, or the messiest, because the subroutine which does all of that checking uses too many different ways to check input validity. I really should work on simplification and efficiency of that subroutine; but currently, the program works well. Later when I have the chance to use the other computer which has the BAS file for desktop_timer_demo_v096, I will copy and post the code. (v 0.96 is much further designed in other ways too, than v 0.9.)
|
|
|
Post by jarych on Jun 28, 2019 18:18:31 GMT
This one is better, being resistant to user input mistakes. The downloadable zipped package is for JB users who are interested in trying the program. The code will be found in the BAS file. (unless someone says he wants to see the code here in the post). Download at this link: download desktop_timer_demo_v096.zip, 11MBI would like to see the bas code, it can't be that much more than 1K versus 11MB? For my alarm clock (we just ran this exercise at another Basic forum) I used hh:mm (hours 0-23) format to compare directly to first 5 characters of TIME$ with no checks because I am only one who uses it and seeing the format is enough of a prompt for an INPUT string$. And for a Timer, I just INPUT minutes that accept fractions to compare with TIME$("ms" or "seconds") depending on if I checking a code time or an event time for myself. Mostly I am interested in your choice of checking input as we discussed elsewhere or you could just say... Thanks B+ and other interested members, see earlier posting, now code is included in the post. Link still is seen in quoted part as well as that earlier message. Code there in the post is broken because of the added and unintended double-spacing. Let me try once more putting in code tag AFTER pasting: 'desktop timer, the name of program and project
'started June 14, 2019
'removing development commentaries for the demonstration package
'desktop_timer_v096
vrshn$=" 0.96"
flagVersion=0
invalidchar$="abcdefghijlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,.?/"
needcharacters$="1234567890" 'put in evening june 27, 2019
dim pickalert$(12) 'which audio alert
'pickalert$(1)="bounce1.wav"
'pickalert$(2)="ringout.wav"
aud$="sounds\bounce1.wav"
dim audname$(12)
gosub [fillsoundelements]
gosub [soundfilenamesonly]
dim alerttime$(5) 'which audio alert time in seconds
alerttime$(1)="15"
alerttime$(2)="30"
alerttime$(3)="45"
alerttime$(4)="60"
alerttime$(5)="75"
audtime$="30"
nomainwin
WindowWidth = 550
WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "minutes part", 30, 66, 144, 20
statictext #main.statictext2, "seconds part", 198, 66, 144, 20
textbox #main.textbox3, 22, 96, 100, 25
textbox #main.textbox4, 190, 96, 100, 25
button #main.button5, "BEGIN", [button5Click], UL, 358, 96, 122, 25
button #main.button7,"STOP ALARM",[stopalarm],UL, 358, 156, 122, 25
statictext #main.statictext6, "MMM:SS", 358, 46, 144, 20
statictext #main.opts,"Options: Sound, Seconds of Sound",22,156,230,20
'combobox #main.pickalert, pickalert$(),[picksound],22,190,100,25
combobox #main.pickalert,audname$(),[picksound],22,190,120,25
combobox #main.pickalerttime, alerttime$(),[picksoundtime],150,190,100,25
button #main.about, "About",[about],UL,22,20,50,20
open "TIMER for your desktop" for window as #main
print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
print #main.statictext6,"!font sans_serif 14"
wait
[quit.main]
flagVersion=0
Close #main
END
[button5Click] 'Perform action for the button named 'button5'
'Insert your own code here
flagready=0
'oneminalert=32 'not sure if the best place, alert to timer end is this many seconds
oneminalert=val(audtime$)
print #main.textbox3,"!contents? M$"
print #main.textbox4,"!contents? S$"
REM check if M$ and S$ inputs are good or bad
gosub [checktimeinputs]
IF flaginputscheck=0 then
NOTICE ""+chr$(13)+"Fix bad or missing time inputs values."
WAIT
END IF
totaltimeseconds=val(M$)*60+val(S$)
notice ""+chr$(13)+str$(totaltimeseconds)+" total seconds"
if totaltimeseconds>0 then flagready=1
timer 1000, [retimeQ]
[retimeQ]
SCAN
totaltimeseconds=totaltimeseconds-1
if totaltimeseconds>=60 then
M=int(totaltimeseconds/60)
S=totaltimeseconds-60*M
else
M=0
S=totaltimeseconds
end if
T$=str$(M)+":"+str$(S)
IF totaltimeseconds<=0 then timer 0
PRINT #main.statictext6,T$
if flagready=1 and totaltimeseconds=0 then
timer 2000,[audioalert]
[audioalert]
'playwave "beep.wav",loop
playwave aud$,loop
oneminalert=oneminalert-2
if oneminalert<=0 then
playwave ""
timer 0
flagready=0
end if
end if
wait
[stopalarm]
'empty until development time
playwave ""
flagready=0
'oneminalert=32
oneminalert=val(audtime$)
timer 0
REM may allow other inputs to remain
REM this only stops timer, alert sound, and changes to countdown display.
REM not a pause
wait
[picksound]
'print #main.pickalert, "contents? aud$"
print #main.pickalert, "selectionindex? v"
let aud$="sounds\"+audname$(v)
wait
[picksoundtime]
print #main.pickalerttime, "contents? audtime$"
wait
[about]
flagVersion=1
notice""+chr$ _
+"desktop timer v "+vrshn$+" - very simple timer" _
+chr$(13)+chr$(13) _
+"" _
+"(c) copyright 2019, jarych" _
+chr$(13)+chr$(13) _
+"Choose mixed minutes & seconds to countdown. " _
+"Left-click 'BEGIN' button. " _
+"If you want to stop the alert sound early then" _
+chr$(13)+"left-click the 'STOP' button." _
+chr$(13)+"A few choices are allowed for alert sound and how long " _
+chr$(13)+"(in seconds) the alert will sound."
wait
'----------------------------------SUBROUTINES-----------------------------
[fillsoundelements]
REM only nine elements this version
pickalert$(1)="sounds\bounce1.wav"
pickalert$(2)="sounds\ringout.wav"
pickalert$(3)="sounds\alarmbuzzer.wav"
pickalert$(4)="sounds\analog-watch.wav"
pickalert$(5)="sounds\CuckooClock.wav"
pickalert$(6)="sounds\low-train-horn.wav"
pickalert$(7)="sounds\old-fashioned-school-bell.wav"
pickalert$(8)="sounds\PageBeeps.wav"
pickalert$(9)="sounds\tolling-bell.wav"
return
[soundfilenamesonly]
REM for easier to read combobox sound selection
REM only show file name without directory path
for a=1 to 9
audname$(a)=mid$(pickalert$(a),8)
next a
'for a0=1 to 9
'print audname$(a0)
'next a0
return
[checktimeinputs] 'this routine is not working.
flaginputscheck=1 'assuming good inputs
if len(M$)=0 and len(S$)=0 then
flaginputscheck=0
goto [jumpout]
end if
if M$="0" or M$="" then
M$="0"
end if
if int(val(M$))<>val(M$) OR int(val(S$))<>val(S$) then
flaginputscheck=0
goto [jumpout]
end if
if val(S$)>60 then
notice ""+chr$+"Use mixed time units Minutes count and Seconds count, and ensure seconds as whole value from 0 to 59."
flaginputscheck=0
end if
if val(M$)>=1 and val(S$)>=60 then
notice ""+chr$(13)+"Such improper mixed units not allowed"
flaginputscheck=0
end if
'---------------------------------------------------this section put in on june 27, 2019 EVENING
REM want to try instr() to look for position of any bad input characters and set flag to 0
REM instr(referencestring,inputstring,placetostart)
for i0=1 to len(M$)
if instr(needcharacters$,mid$(M$,i0,1))=0 then
flaginputscheck=0
end if
next i0
for i1=1 to len(S$)
if instr(needcharacters$,mid$(S$,i1,1))=0 then
flaginputscheck=0
end if
next i1
'------------------------------------------------------------------
[jumpout]
rem decision on action for validity should occur in the button's branch.
return
|
|
|
Post by B+ on Jun 28, 2019 20:17:40 GMT
Thanks
Oh hey, nice list of sound effects!
|
|
|
Post by jarych on Jun 28, 2019 20:19:49 GMT
Note that if you click on the link to download the file, you CAN download it, even if you first see a message showing this:
If you are trying to download my package, then if you get that message, just click on the blue Download button.
|
|
|
Post by jarych on Jul 1, 2019 10:02:58 GMT
download zipped demonstration package desktop_timer_v09710525 kb zipped file size Updated the demonstration program to desktop_timer_demo_v097, and uploading to the JB Proboards Forum. Improved input focus control code modified for check of user input mistakes audio alert sounds are in included folder 9 audio alert choices 5 audio alert play time choices Slightly more than 1 MegaByte - I cannot upload here - another arrangement is in process now... See link shown above.
|
|
|
Post by jarych on Jul 9, 2019 10:40:21 GMT
Another update for desktop_timer, a simple desktop timer , countdown and then alert-sound plays. Not thoroughy tested but only short testing enough to correct apparent initial problems of reliability. Alert sound choice, and alert sound play time options are now kept in a file. New icon included for show but JB2 users may write this into their copy of run.exe file on their own.\ Copy of the code is included in a text file, instead of giving the BAS file. New zipped file here, this post. desktop_timer_v098.zip (7.69 KB) vrshn$=" 0.98" flagVersion=0 needcharacters$="1234567890" 'put in evening june 27, 2019
rem establish or read options file open "dt_options.dat" for append as #o close #o open "dt_options.dat" for input as #p sizeopt=lof(#p) close #p if sizeopt<17 then aud$="sounds\bounce1.wav" audtime$="30" open "dt_options.dat" for output as #t print #t,aud$ print #t,audtime$ close #t end if
dim pickalert$(12) 'which audio alert
'aud$="sounds\bounce1.wav" dim audname$(12) gosub [fillsoundelements] gosub [soundfilenamesonly] dim alerttime$(5) 'which audio alert time in seconds alerttime$(1)="15" alerttime$(2)="30" alerttime$(3)="45" alerttime$(4)="60" alerttime$(5)="75" 'audtime$="30"
rem NOW see the options from file gosub [seeoptions]
nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "minutes part", 30, 66, 144, 20 statictext #main.statictext2, "seconds part", 198, 66, 144, 20 textbox #main.textbox3, 22, 96, 100, 25 textbox #main.textbox4, 190, 96, 100, 25 button #main.button5, "BEGIN", [button5Click], UL, 358, 96, 122, 25 button #main.button7,"STOP ALARM",[stopalarm],UL, 358, 156, 122, 25 statictext #main.statictext6, "MMM:SS", 358, 46, 144, 20 statictext #main.opts,"Options: Sound, Seconds of Sound",22,156,230,20 'combobox #main.pickalert, pickalert$(),[picksound],22,190,100,25 combobox #main.pickalert,audname$(),[picksound],22,190,120,25 combobox #main.pickalerttime, alerttime$(),[picksoundtime],150,190,100,25 button #main.about, "About",[about],UL,22,20,50,20 open "TIMER for your desktop" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10" print #main.statictext6,"!font sans_serif 14"
print #main.textbox3,"!setfocus"
wait
[quit.main] flagVersion=0 gosub [setoptions] Close #main END
[button5Click] 'Perform action for the button named 'button5' flagready=0 'oneminalert=32 'not sure if the best place, alert to timer end is this many seconds oneminalert=val(audtime$) print #main.textbox3,"!contents? M$" print #main.textbox4,"!contents? S$" REM check if M$ and S$ inputs are good or bad gosub [checktimeinputs] IF flaginputscheck=0 then NOTICE ""+chr$(13)+"Fix bad or missing time inputs values." WAIT END IF
print #main.button7,"!setfocus" totaltimeseconds=val(M$)*60+val(S$)
notice ""+chr$(13)+str$(totaltimeseconds)+" total seconds" if totaltimeseconds>0 then flagready=1
timer 1000, [retimeQ] [retimeQ] SCAN totaltimeseconds=totaltimeseconds-1 if totaltimeseconds>=60 then M=int(totaltimeseconds/60) S=totaltimeseconds-60*M else M=0 S=totaltimeseconds end if T$=str$(M)+":"+str$(S) IF totaltimeseconds<=0 then timer 0
PRINT #main.statictext6,T$
if flagready=1 and totaltimeseconds=0 then timer 2000,[audioalert] [audioalert] 'playwave "beep.wav",loop playwave aud$,loop oneminalert=oneminalert-2 if oneminalert<=0 then playwave "" timer 0 flagready=0 end if end if
wait
[stopalarm] 'empty until development time playwave "" flagready=0 'oneminalert=32 oneminalert=val(audtime$) timer 0 REM may allow other inputs to remain REM this only stops timer, alert sound, and changes to countdown display. REM not a pause wait
[picksound] print #main.pickalert, "selectionindex? v" let aud$="sounds\"+audname$(v) wait
[picksoundtime] print #main.pickalerttime, "contents? audtime$" wait
[about] flagVersion=1 notice""+chr$ _ +"desktop timer v "+vrshn$+" - very simple timer" _ +chr$(13)+chr$(13) _ +"" _ +"(c) copyright 2019, jarych" _ +chr$(13)+chr$(13) _ +"Choose mixed minutes & seconds to countdown. " _ +"Left-click 'BEGIN' button. " _ +"If you want to stop the alert sound early then" _ +chr$(13)+"left-click the 'STOP' button." _ +chr$(13)+"A few choices are allowed for alert sound and how long " _ +chr$(13)+"(in seconds) the alert will sound." wait
'----------------------------------SUBROUTINES-----------------------------
[fillsoundelements] REM only nine elements this version
pickalert$(1)="sounds\bounce1.wav" pickalert$(2)="sounds\ringout.wav" pickalert$(3)="sounds\alarmbuzzer.wav" pickalert$(4)="sounds\analog-watch.wav" pickalert$(5)="sounds\CuckooClock.wav" pickalert$(6)="sounds\low-train-horn.wav" pickalert$(7)="sounds\old-fashioned-school-bell.wav" pickalert$(8)="sounds\PageBeeps.wav" pickalert$(9)="sounds\tolling-bell.wav"
return
[soundfilenamesonly] REM for easier to read combobox sound selection REM only show file name without directory path
for a=1 to 9 audname$(a)=mid$(pickalert$(a),8) next a 'for a0=1 to 9 'print audname$(a0) 'next a0 return
[checktimeinputs] 'this routine is not working. flaginputscheck=1 'assuming good inputs
if M$="" then M$="0" if S$="" then S$="0"
if M$="0" and S$="0" then flaginputscheck=0 goto [jumpout] end if
if val(M$)>=1 and val(S$)>=60 then notice ""+chr$(13)+"Such improper mixed units not allowed" flaginputscheck=0 end if '---------------------------------------------------this section put in on june 27, 2019 EVENING REM want to try instr() to look for position of any bad input characters and set flag to 0 REM instr(referencestring,inputstring,placetostart) for i0=1 to len(M$) if instr(needcharacters$,mid$(M$,i0,1))=0 then flaginputscheck=0 end if next i0 for i1=1 to len(S$) if instr(needcharacters$,mid$(S$,i1,1))=0 then flaginputscheck=0 end if next i1 '------------------------------------------------------------------
[jumpout] rem decision on action for validity should occur in the button's branch. return
[setoptions] open "dt_options.dat" for output as #opt print #opt,aud$ print #opt,audtime$ close #opt return
[seeoptions] open "dt_options.dat" for input as #oo input #oo,aud$ input #oo,audtime$ close #oo return
|
|
|
Post by jarych on Jul 12, 2019 21:48:14 GMT
One very small change to improve the seconds of time output display - very very small code adjustment. Most of the development commentary notes have been removed here, for version 0.98a demonstration edition:
'(c) 2019, jarych 'desktop_timer_v098a.bas [retimeQ] needs a USING() to manage leading zero if number is one digit. 'Fixed with the two decision line for S; Not Need USING() function 'July 12, 2019
vrshn$=" 0.98a" flagVersion=0 needcharacters$="1234567890" 'put in evening june 27, 2019
rem establish or read options file open "dt_options.dat" for append as #o close #o open "dt_options.dat" for input as #p sizeopt=lof(#p) close #p if sizeopt<17 then aud$="sounds\bounce1.wav" audtime$="30" open "dt_options.dat" for output as #t print #t,aud$ print #t,audtime$ close #t end if
dim pickalert$(12) 'which audio alert
'aud$="sounds\bounce1.wav" dim audname$(12) gosub [fillsoundelements] gosub [soundfilenamesonly] dim alerttime$(5) 'which audio alert time in seconds alerttime$(1)="15" alerttime$(2)="30" alerttime$(3)="45" alerttime$(4)="60" alerttime$(5)="75" 'audtime$="30"
rem NOW see the options from file gosub [seeoptions]
nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "minutes part", 30, 66, 144, 20 statictext #main.statictext2, "seconds part", 198, 66, 144, 20 textbox #main.textbox3, 22, 96, 100, 25 textbox #main.textbox4, 190, 96, 100, 25 button #main.button5, "BEGIN", [button5Click], UL, 358, 96, 122, 25 button #main.button7,"STOP ALARM",[stopalarm],UL, 358, 156, 122, 25 statictext #main.statictext6, "MMM:SS", 358, 46, 144, 20 statictext #main.opts,"Options: Sound, Seconds of Sound",22,156,230,20 'combobox #main.pickalert, pickalert$(),[picksound],22,190,100,25 combobox #main.pickalert,audname$(),[picksound],22,190,120,25 combobox #main.pickalerttime, alerttime$(),[picksoundtime],150,190,100,25 button #main.about, "About",[about],UL,22,20,50,20 open "TIMER for your desktop" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10" print #main.statictext6,"!font sans_serif 14"
print #main.textbox3,"!setfocus"
wait
[quit.main] flagVersion=0 gosub [setoptions] Close #main END
[button5Click] 'Perform action for the button named 'button5' flagready=0 'oneminalert=32 'not sure if the best place, alert to timer end is this many seconds oneminalert=val(audtime$) print #main.textbox3,"!contents? M$" print #main.textbox4,"!contents? S$" REM check if M$ and S$ inputs are good or bad gosub [checktimeinputs] IF flaginputscheck=0 then NOTICE ""+chr$(13)+"Fix bad or missing time inputs values." WAIT END IF
print #main.button7,"!setfocus" totaltimeseconds=val(M$)*60+val(S$)
notice ""+chr$(13)+str$(totaltimeseconds)+" total seconds" if totaltimeseconds>0 then flagready=1
timer 1000, [retimeQ] [retimeQ] SCAN totaltimeseconds=totaltimeseconds-1 if totaltimeseconds>=60 then M=int(totaltimeseconds/60) S=totaltimeseconds-60*M else M=0 S=totaltimeseconds end if 'T$=str$(M)+":"+str$(S) 'T$=str$(M)+":"+using("##",S) 'test to see if this works; not exactly; gives just space if num is one digit IF S<10 THEN T$=str$(M)+":"+"0"+str$(S) IF S>=10 THEN T$=str$(M)+":"+str$(S) IF totaltimeseconds<=0 then timer 0
PRINT #main.statictext6,T$
if flagready=1 and totaltimeseconds=0 then timer 2000,[audioalert] [audioalert] 'playwave "beep.wav",loop playwave aud$,loop oneminalert=oneminalert-2 if oneminalert<=0 then playwave "" timer 0 flagready=0 end if end if
wait
[stopalarm] 'empty until development time playwave "" flagready=0 'oneminalert=32 oneminalert=val(audtime$) timer 0 REM may allow other inputs to remain REM this only stops timer, alert sound, and changes to countdown display. REM not a pause wait
[picksound] print #main.pickalert, "selectionindex? v" let aud$="sounds\"+audname$(v) wait
[picksoundtime] print #main.pickalerttime, "contents? audtime$" wait
[about] flagVersion=1 notice""+chr$ _ +"desktop timer v "+vrshn$+" - very simple timer" _ +chr$(13)+chr$(13) _ +"" _ +"(c) copyright 2019, jarych" _ +chr$(13)+chr$(13) _ +"Choose mixed minutes & seconds to countdown. " _ +"Left-click 'BEGIN' button. " _ +"If you want to stop the alert sound early then" _ +chr$(13)+"left-click the 'STOP' button." _ +chr$(13)+"A few choices are allowed for alert sound and how long " _ +chr$(13)+"(in seconds) the alert will sound." wait
'----------------------------------SUBROUTINES-----------------------------
[fillsoundelements] REM only nine elements this version
pickalert$(1)="sounds\bounce1.wav" pickalert$(2)="sounds\ringout.wav" pickalert$(3)="sounds\alarmbuzzer.wav" pickalert$(4)="sounds\analog-watch.wav" pickalert$(5)="sounds\CuckooClock.wav" pickalert$(6)="sounds\low-train-horn.wav" pickalert$(7)="sounds\old-fashioned-school-bell.wav" pickalert$(8)="sounds\PageBeeps.wav" pickalert$(9)="sounds\tolling-bell.wav"
return
[soundfilenamesonly] REM for easier to read combobox sound selection REM only show file name without directory path
for a=1 to 9 audname$(a)=mid$(pickalert$(a),8) next a 'for a0=1 to 9 'print audname$(a0) 'next a0 return
[checktimeinputs] 'this routine is not working. flaginputscheck=1 'assuming good inputs
if M$="" then M$="0" if S$="" then S$="0"
if M$="0" and S$="0" then flaginputscheck=0 goto [jumpout] end if
if val(M$)>=1 and val(S$)>=60 then notice ""+chr$(13)+"Such improper mixed units not allowed" flaginputscheck=0 end if '---------------------------------------------------this section put in on june 27, 2019 EVENING REM want to try instr() to look for position of any bad input characters and set flag to 0 REM instr(referencestring,inputstring,placetostart) for i0=1 to len(M$) if instr(needcharacters$,mid$(M$,i0,1))=0 then flaginputscheck=0 end if next i0 for i1=1 to len(S$) if instr(needcharacters$,mid$(S$,i1,1))=0 then flaginputscheck=0 end if next i1 '------------------------------------------------------------------
[jumpout] rem decision on action for validity should occur in the button's branch. return
[setoptions] open "dt_options.dat" for output as #opt print #opt,aud$ print #opt,audtime$ close #opt return
[seeoptions] open "dt_options.dat" for input as #oo input #oo,aud$ input #oo,audtime$ close #oo return
For those very few who have tried my earlier version or package, still need to include the sounds\ folder in the same directory.
|
|