Topic: CountDown

Thanks to EHW and other kind guys here, we have a working Stopwatch.
http://myvisualdatabase.com/forum/viewtopic.php?id=3881


I took Derek's alternative stopwatch and tried to make a CountDown timer. As usual, couldn't get it working. Please see the attached sample project.
Could somebody code it together with it's settings please?
♦ On settings it'd be great if .mp3 sound files supported beside .wav
♦ I used hard coded combox lists so that user can type or choose from combboxes count up to times.

Post's attachments

Attachment icon CountDown2.zip 16.19 kb, 411 downloads since 2017-11-24 

Adam
God... please help me become the person my dog thinks I am.

Re: CountDown

found a post in Russian forum.

http://myvisualdatabase.com/forum/viewtopic.php?id=3211

Re: CountDown

Thanks a lot nrmuduli but thats not exactly what I was looking for.

Adam
God... please help me become the person my dog thinks I am.

4 (edited by derek 2017-11-28 00:18:10)

Re: CountDown

Hi Adam,
I'm not sure if this is the sort of thing that you're after (please see attached).  I've bolted it together from bits of old code from other projects.  It doesn't have all the 'bells and whistles' that you probably want (for example, changing colour schemes - nice one EHW) but the core functionality is probably okay.  And it will need some validation checks putting in at some stage.
Anyway, maybe it will give you some ideas?
Regards,
Derek.

Post's attachments

Attachment icon Derek StopWatch.zip 341.14 kb, 467 downloads since 2017-11-28 

5 (edited by AD1408 2017-11-27 05:22:56)

Re: CountDown

Hi Derek,


Thank you very much...........................
It was nice touch to add elapsed time. Truly appreciated....................


I have tried to apply your script to my version but I got  not valid integer error loop and I couldn't correct it.
Please see the attached sample project.


------------------------------
Edit:
Main issue seems to be with comboboxes. Tried various things without any success.

Post's attachments

Attachment icon CountDown2 B.zip 16.91 kb, 401 downloads since 2017-11-25 

Adam
God... please help me become the person my dog thinks I am.

Re: CountDown

hii,
pls. check

Post's attachments

Attachment icon CountDown2 B.zip 15.9 kb, 402 downloads since 2017-11-27 

Re: CountDown

nrmuduli wrote:

hii,
pls. check


Still get same "" not valid integer error at my end

Adam
God... please help me become the person my dog thinks I am.

8 (edited by nrmuduli 2017-11-27 10:56:28)

Re: CountDown

at my end it works
checked with v4.02 trail

i have removed some components & modify the script. so pls. do not replace your script with this script

Post's attachments

Attachment icon cdown.png 48.38 kb, 230 downloads since 2017-11-27 

9 (edited by derek 2017-11-27 11:18:20)

Re: CountDown

Hi Adam, Nrmuduli,
Not had time to go through the script but I imagine a 'not valid integer' error message would occur when you run it without having selected a time from the comboboxes (ie blank hours, blank minutes and blank seconds) which should be easy enough to trap. 
Running it with 00 hours, 00 minutes and 00 seconds (rather than blanks) stops the 'not valid integer' message but then takes your counter into negative (again, should be easy enough to trap).
Regards,
Derek.

10 (edited by AD1408 2017-11-27 13:09:18)

Re: CountDown

Hi nrmuduli,
I'm using MVD 3.5


Hi Derek,

... I imagine a 'not valid integer' error message would occur when you run it without having selected a time from the comboboxes (ie blank hours, blank minutes and blank seconds)...

It seems it's the case.


I tried:

procedure Form1_OnShow (Sender: TObject; Action: string);
begin
  form1.cbHours.text := '00';
  form1.cbMinutes.text := '00';
  form1.cbSeconds.text := '00';
end;

It didn't work, still got blank combo boxes on form1 show.


Here is my latest version of the countdown project, if needed. It only works if manually combo values selected.

Post's attachments

Attachment icon CountDown2 B Combo.zip 18.18 kb, 406 downloads since 2017-11-27 

Adam
God... please help me become the person my dog thinks I am.

11 (edited by derek 2017-11-27 13:47:52)

Re: CountDown

Hi Adam,
In your Form1_onshow, I'd probably go with
  form1.cbhours.itemindex   := 0;
  form1.cbminutes.ItemIndex := 0;
  form1.cbseconds.itemindex := 0;
You could also set form1.cbseconds.itemindex := 1; and use the same code to prevent the clock going negative (it wouldn't stop the user from deliberately doing it - for whatever reason - but would prevent it accidently happening).  Please see attached.
Derek.

Post's attachments

Attachment icon CountDown2 B Combo.zip 350.99 kb, 436 downloads since 2017-11-27 

Re: CountDown

Hi Derek,


Thank you very much..............
Truly appreciated ......................


Good thinking on preventing the clock going negative. Also added negative prevention to Reset button, so that it resets to 01 instead of 00


I did try ItemIndex also but on the wrong place, before combo items.add lines. I'm searching ways to inject another cell into my brain as single cell fails me often.


Next, I'll try to apply EHW's code from StopWatch for settings screen.

Adam
God... please help me become the person my dog thinks I am.

13 (edited by AD1408 2017-11-28 11:11:23)

Re: CountDown

I have tried to apply EHW's settings code (changing display colors) but I get couple of errors.
"" not valid integer error under frmSettings_OnShow event starting at line 301, commented out.
♦ I couldn't understand the code between
   begin
   ....
   end.
   fully. It crashes the app on compile. Commented out.


I'm hoping that EHW is around and have some free time finish settings fully (Sound and Display tabs settings items)...
Or any other kind person who can do it...
It has been great learning exercise, at least for me.


Please see the attached latest CountDown project:

Post's attachments

Attachment icon CountDown3 Combo wSettings1.zip 24.03 kb, 401 downloads since 2017-11-28 

Adam
God... please help me become the person my dog thinks I am.

14 (edited by ehwagner 2017-11-29 05:11:54)

Re: CountDown

Adam,
I put the settings code in for you. I wasn't sure what the purpose is for the countUP table. I did not do anything with that. Maybe you were thinking of saving the last time entries. If so, I can put that together for you also, but I would probably put those entries in the settings file. The countUP table would not be necessary.


I put a Sounds folder in the project with a sound file in it for you to test the sound functionality. I also placed the color dialog picker in a function (GetColor) so the color dialog code does not need to be repeated for every selection. In addition I used a For loop to load the comboboxes in Form1 instead of hard coding all the entries. The result is the same. It's just less code and less typing.

Post's attachments

Attachment icon CountDown3 Combo wSettings Revised.zip 632.36 kb, 457 downloads since 2017-11-29 

Re: CountDown

Hi EHW.


GREAT Stuff !!!
Thank you very much.............................
Truly appreciated...........................


... I wasn't sure what the purpose is for the countUP table. I did not do anything with that....

Knowledge shortage at my part. I was thinking those text fields as combo items value holder but now after your pointing out there is no need to save them in this situation.


Extra thank you for trimming the script in respect of combo items and color dialog. More learning references for me.


I couldn't understand how you get/define values (numbers and "") in line below? If you could explain id'd be appreciated.

If SqlExecute('Select Count(id) From Settings') = 0 then SqlExecute('Insert Into Settings Values (1,65280,0,65280,65280,0,0,0,0,0,16776960,16776960,16776960,"")');

I wanted replace system error/info dialog messages below wit a user friendly versions on settings form:
Clicking on Play button when play sound checkbox is checked and sound file edit field has no sound file
"Cannot determine the device type from the given filename extention."
and stop button
"No MCI device open."


I tried Dmitry's code for foreign key retraints but didn't work. I suspect function is incorrect:

function OnSQLException(Sender: TObject; Msg: string; SQL: string): boolean;
begin
if Sender = frmSettings.btnPlay then
   begin
   if Pos('Cannot determine the device type from the given filename extention.', Msg)=1 then
      begin
      result := True;
      MessageBox('No sound file was selected. Please select a .mp3 or .wav sound file first by clicking on Sound File button.', 'Error', MB_OK+MB_ICONWARNING);
      end;
   end;
end;

I ended up disabling/enabling play and stop buttons, which may not be a proper solution:

procedure frmSettings_cBoxPlaySound_OnClick (Sender: TObject);
If (frmSettings.cBoxPlaySound.Checked = True) and (frmSettings.edSoundFile.Text <>'') then
   begin
   frmSettings.btnPlay.Enabled := True;
   frmSettings.btnStop.Enabled := True;
   end else;

If (frmSettings.cBoxPlaySound.Checked = True) and (frmSettings.edSoundFile.Text = '') then
   begin
   frmSettings.btnPlay.Enabled := False;
   frmSettings.btnStop.Enabled := False;
   end;
end;

procedure frmSettings_edSoundFile_OnChange (Sender: TObject);
begin
If (frmSettings.cBoxPlaySound.Checked = True) and (frmSettings.edSoundFile.Text <>'') then
   begin
   frmSettings.btnPlay.Enabled := True;
   frmSettings.btnStop.Enabled := True;
   end else;

If (frmSettings.cBoxPlaySound.Checked = True) and (frmSettings.edSoundFile.Text = '') then
   begin
   frmSettings.btnPlay.Enabled := False;
   frmSettings.btnStop.Enabled := False;
   end;
end;

Once again thank you so much for your kind help...............................

Adam
God... please help me become the person my dog thinks I am.

16 (edited by ehwagner 2017-11-29 16:56:27)

Re: CountDown

Values (1,65280,0,65280,65280,0,0,0,0,0,16776960,16776960,16776960,"")');

The values between the commas typically follow your database table definition in MVD. However, I noticed that the definition in your MVD table definition for Settings does not exactly match the actual table definition. Somewhere along the way you must have moved around the column definitions in MVD. Doing so is fine, but the actual database definition order does not get changed outside of MVD. Using a tool like SqlLiteStudio, you will see the actual field definition order. I don't mean to confuse you on this. If I would have placed the actual field names as part of the SQL "Insert", it wouldn't have mattered about the field order. Just laziness on my part.


Here are the values for each field in the table:
1 = id
65280       = clLime color code for cdColorTextHRS
0               = clBlack color code for cdColorBgHRS
65280       = clLime color code for cdColorTextMINS
65280       = clLime color code for cdColorTextSECS
0               = clBlack color code for cdColorBgMINS
0               = clBlack color code for cdColorBgSECS
0               = clBlack color code for etColorBgHRS
0               = clBlack color code for etColorBgMINS
0               = clBlack color code for etColorBgSECS
16776960 = clAqua color code for etColorTextHRS
16776960 = clAqua color code for etColorTextMINS
16776960 = clAqua color code for etColorTextSECS
""              = Null value for SoundFile


Disabling/Enabling the Play and Stop buttons is good solution. I actually meant to do that for you. This will eliminate the need to intercept the error because the error should never occur because these buttons cannot be clicked when there is no sound file to play..

17 (edited by AD1408 2017-11-30 16:19:21)

Re: CountDown

Thank you very much for the explanation EHW. As always truly appreciated.....


I like to add couple more features to countdow timer for learning purposes.


1. Progress bar.
Tried to follow Dmitry's code but couldn't get it working.


2. Currently single message displayed when countdown finishes.
Could we get it display some hard coded or db table lookup style random messages. Different one per countdown? Such as:
form1.LabelFinished.caption := 'Eagle has landed';
//form1.LabelFinished.caption := 'Godot has arrived';
//form1.LabelFinished.caption := 'Finished spinning wheel';
//form1.LabelFinished.caption := 'Mercury is conquered';
If done via db table lookup style using form settings with new tab sheet, where user can enter their own finished messages; may present some extra work in respect of limiting message characters counts so that they fit in message panel on form1


3. Flashing text effect for finished caption text
Nothing fancy. Just a repeating two color changes with short intervals so that it gives flashing effect.


Latest version of the CountDown project I have is attached:

Post's attachments

Attachment icon CountDown 4.zip 56.1 kb, 387 downloads since 2017-11-30 

Adam
God... please help me become the person my dog thinks I am.

18 (edited by derek 2017-11-30 18:15:56)

Re: CountDown

Hi Adam,
At its most basic, I'd use a table (messages) with 2 columns - 1 column for the message itself and 1 column to hold a flag to say whether it's to be used or not..  If you're talking multi-user, you could link it to a userid table so that each user had their own set of messages (useful in a multilingual environment) - I guess it really depends how far you want to take it.
With message length, I'd just use the column heading in the tablegrid to inform users that the maximum length of message is NN - but, you could do the job more thoroughly and trap for input greater than NN characters and display an error message.
As always with MVD, probably lots of other ways to do it too.
Derek.

Post's attachments

Attachment icon CountDown 4.zip 389.98 kb, 428 downloads since 2017-11-30 

Re: CountDown

Hi Derek,


Thank you very much....


Unless I'm missing something you worked on item 2.
That's not what I meant. Most likely my explanation was not clear.
I would like to display random message in random order, every time countdown finishes. In this respect we don't need a use column as messages displayed randomly.

Say we have 10 messages entered to tGrid
First countdown 1st message
Second countdown 2nd message
....
Tenth countdown 10th message

Eleventh countdown starts with 5th message (this time it starts somewhere middle)
uses 5 + messages upto available 10 messages then 5 minus up to and including message 1

21st countdown starts with i.e. 8th message then count up or down until available messages used

31st countdown starts with i.e. 4th message count up or down until available messages used

an so on....

In order to reduce predictability in certain degree.

Adam
God... please help me become the person my dog thinks I am.

20 (edited by derek 2017-12-01 10:05:18)

Re: CountDown

Does something like this give you what you want? (just item 2 from your post).
form1.labelfinished.caption := sqlexecute('select message from messages order by random()');
Derek.

Post's attachments

Attachment icon CountDown 4.zip 390.09 kb, 404 downloads since 2017-12-01 

Re: CountDown

Hi Derek,


Thank you very much..............
I also added your line

form1.labelfinished.caption := sqlexecute('select message from messages order by random()'); 

under Form1_btnReset_OnClick


Only thing remains for item 2 is limiting message characters. It's fine using table header as info flag but as you know user will overlook and type longer messages. As you said "... but, you could do the job more thoroughly and trap for input greater than NN characters and display an error message."
Unfortunately, I don't know how to code trapping input.

Adam
God... please help me become the person my dog thinks I am.

Re: CountDown

There are different ways but I'd use 'gettextlen'.
If the entered text is greater than will fit in your label, you can show a message or, as I've done in the example, simple hide the 'save' button until the text length is reduced to the permitted length.
Derek.

Post's attachments

Attachment icon CountDown 4.zip 391.23 kb, 396 downloads since 2017-12-01 

23 (edited by AD1408 2017-12-01 22:20:05)

Re: CountDown

Thank you very much Derek.................
Truly appreciated.............


Thanks to Derek item 2 is done.


Now remaining items are:
1. Progress bar.
Tried to follow Dmitry's code but couldn't get it working.


3. Flashing text effect for finished caption text
Nothing fancy. Just a repeating two color changes with short intervals so that it gives flashing effect.

Adam
God... please help me become the person my dog thinks I am.

Re: CountDown

Adam,
Just one small change to Item 2 - to help the user, you might also want to keep a running count of how many characters are in the message (see attached).
Derek.

Post's attachments

Attachment icon CountDown 5.zip 391.85 kb, 417 downloads since 2017-12-01 

25 (edited by AD1408 2017-12-01 22:33:50)

Re: CountDown

Thank you very much Derek........


Running count is a nice touch. Appreciated.
I also added running count below message box using labels.


Remaining items are:
1. Progress bar.
Tried to follow Dmitry's code but couldn't get it working.


3. Flashing text effect for finished caption text
Nothing fancy. Just a repeating two color changes with short intervals so that it gives flashing effect.


Latest version of the CountDown project I have is attached:

Post's attachments

Attachment icon CountDown 5a.zip 59.36 kb, 430 downloads since 2017-12-01 

Adam
God... please help me become the person my dog thinks I am.