home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / progs / CB / DATA.Z / WPMMAIN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-29  |  2.4 KB  |  77 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "wpmmain.h"
  6. #include <ctype.h>
  7. //---------------------------------------------------------------------------
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12.   : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TForm1::StartTimer(TObject *Sender, Word &Key,
  17.       TShiftState Shift)
  18. {
  19.     if (RichEdit1->ReadOnly == false)
  20.     {
  21.         Timer1->Enabled = True;
  22.         Label1->Caption = "Test Started";
  23.         Label1->Font->Color = clGreen;
  24.     }
  25. }
  26. //---------------------------------------------------------------------
  27. void __fastcall TForm1::IncrementBar(TObject *Sender)
  28. {
  29.     if (ProgressBar1->Position == 59)
  30.     {
  31.         Timer1->Enabled = False;
  32.         Label1->Caption = "Test Complete";
  33.         Label1->Font->Color = clRed;
  34.         RichEdit1->ReadOnly = True;
  35.         Label2->Caption = IntToStr(CalculateWPM()) + " Words Per Minute";
  36.     }
  37.     ProgressBar1->StepIt();
  38. }
  39. //---------------------------------------------------------------------
  40. void __fastcall TForm1::Button2Click(TObject *Sender)
  41. {
  42.     Application->Terminate();
  43. }
  44. //---------------------------------------------------------------------
  45. void __fastcall TForm1::Button1Click(TObject *Sender)
  46. {
  47.         Timer1->Enabled = False;
  48.         Label1->Caption = "Start typing to begin test";
  49.         Label1->Font->Color = clBlack;
  50.         Label2->Caption = "";
  51.         RichEdit1->SetTextBuf("");
  52.         RichEdit1->ReadOnly = False;
  53.         ProgressBar1->Position = 0;
  54. }
  55. //---------------------------------------------------------------------
  56. int __fastcall TForm1::CalculateWPM(void)
  57. {
  58.     int character=0;            // for iterating through text by character
  59.     int count=0;                // for keeping track of the number of words
  60.     bool betweenwords=true;     // for state information while scanning
  61.  
  62.     while ((RichEdit1->Lines->Text.c_str()[character++] != NULL))
  63.     {
  64.         if (isalnum(RichEdit1->Lines->Text.c_str()[character]))
  65.         {
  66.             if (betweenwords)
  67.             {
  68.                 betweenwords = false;
  69.                 count++;
  70.             }
  71.         } else {
  72.             betweenwords = true;
  73.         }
  74.     }
  75.     return count;
  76. }
  77. //---------------------------------------------------------------------