none
Calculate Words per Minute

    Question

  • I want to develop a typing tutor that displays words per minute as you type. Which formula would be best to use for this?

    a&h

    Friday, February 17, 2012 9:20 AM

Answers

  • Hi heinkasner,

    Check out this sample I write for you, the average input speed is displayed in the Form title in real time:
            int wordsCount, ticks = 0;
            System.Windows.Forms.Timer timer;
    
            public Form1()
            {
                InitializeComponent();
    
                textBox1.Multiline = true;
    
                timer = new System.Windows.Forms.Timer();
                timer.Interval = 100;
                timer.Tick += new EventHandler(timer_Tick);
            }
    
            void timer_Tick(object sender, EventArgs e)
            {
                ticks++;
                this.Text = (Math.Round((double)wordsCount / ticks * 60 * 10, 2)).ToString() + " words/mim";
            }
    
            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!timer.Enabled)
                    timer.Enabled = true;
    
                char[] splitKeys = {
                                        ',',
                                        '.',
                                        '?',
                                        ';',
                                        '(',
                                        ')',
                                        ' ',
                                        '\r',
                                        '\n'
                                   };
    
                wordsCount = textBox1.Text.Split(splitKeys, StringSplitOptions.RemoveEmptyEntries).Length;
            }

    Have a nice day,

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, February 21, 2012 12:28 PM
    Moderator

All replies

  • Hi,

    this is the simplest way that i can imagine.

    DateTime? _start = null; int _words = 0; int _wordcount = 0; System.Windows.Forms.Timer _tmr = new System.Windows.Forms.Timer(); string _lastDigited = string.Empty; private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { if (!string.IsNullOrEmpty(_lastDigited)) { _lastDigited = string.Empty; _words++; if (_start == null) { _start = DateTime.Now; _tmr.Interval = 60000; _tmr.Tick += new EventHandler(_tmr_Tick); _tmr.Enabled = true; } } } else _lastDigited += e.KeyCode.ToString(); } void _tmr_Tick(object sender, EventArgs e) {

    //_wordcount is the actual word count per minute _wordcount = _words; _tmr.Stop(); }



    Bilhan silva

    Friday, February 17, 2012 9:40 AM
  • The way typists used to be timed was to give them a piece of text of known length and then set them off. At the end of a time period (e.g. 5 mins) they stopped even if not finished.

    There were also different levels - some tests had longer words or particlar vocabularies (e.g. legal or medical).

    So there is no general formula as far as I know - you need a piece of text that contains a known number of words of varying length and a stopwatch.


    Regards David R
    ---------------------------------------------------------------
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Friday, February 17, 2012 10:43 AM
  • Simply start a timer with interval of 1 minute. In the Tick event handler, just count the words in the textbox using below split function. No, formula is needed.

    int Count = textBox1.Text.Split(new String[] { " ", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Length;

    I hope this helps.

    Please mark this post as answer if it solved your problem. Happy Programming!

    • Proposed as answer by Norkk Friday, February 17, 2012 11:32 AM
    Friday, February 17, 2012 11:27 AM
  • Hi heinkasner,

    Check out this sample I write for you, the average input speed is displayed in the Form title in real time:
            int wordsCount, ticks = 0;
            System.Windows.Forms.Timer timer;
    
            public Form1()
            {
                InitializeComponent();
    
                textBox1.Multiline = true;
    
                timer = new System.Windows.Forms.Timer();
                timer.Interval = 100;
                timer.Tick += new EventHandler(timer_Tick);
            }
    
            void timer_Tick(object sender, EventArgs e)
            {
                ticks++;
                this.Text = (Math.Round((double)wordsCount / ticks * 60 * 10, 2)).ToString() + " words/mim";
            }
    
            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!timer.Enabled)
                    timer.Enabled = true;
    
                char[] splitKeys = {
                                        ',',
                                        '.',
                                        '?',
                                        ';',
                                        '(',
                                        ')',
                                        ' ',
                                        '\r',
                                        '\n'
                                   };
    
                wordsCount = textBox1.Text.Split(splitKeys, StringSplitOptions.RemoveEmptyEntries).Length;
            }

    Have a nice day,

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, February 21, 2012 12:28 PM
    Moderator