Hi RanaAyaz,
I have created a sample which full fill your requirement you need to modify the code according to your need.
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _925078_TypingSpeed
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] data;
int startTime = 0;
private void Form1_Load(object sender, EventArgs e)
{
textBox2.Text = "When the test first starts up, it will present you with a choice of lesson and time. If you are in a hurry, choose the 1 Minute Timed Typing Test. For a more accurate assessment, choose the 5 Minute Test. Lessons 26-35 are the classic story lessons and can make a better overall assessment by typing natural sentences. All the other lessons are available, so if you want to see what your wpm is on the home row keys, or your speed in the 10-key you can. New lessons 38 through 40 include Spanish, French, Russian, Hindi and German words.";
data = textBox2.Text.Split(' ');
textBox2.ReadOnly = true;
label8.Text = "60";
}
private void timer1_Tick(object sender, EventArgs e)
{
startTime = startTime + 1000;
label8.Text = Convert.ToString(Convert.ToInt32(label8.Text) - 1);
if (startTime >= 60000)
{
CalculateAccuracy();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
timer1.Enabled = true;
if (startTime >= 60000)
{
CalculateAccuracy();
}
}
private void CalculateAccuracy()
{
int correctWords = 0;
int incorrectWords = 0;
string output = textBox1.Text;
string[] str = output.Split(' ');
for (int j = 0; j < str.Length; j++)
{
if (str[j] == data[j])
{
correctWords++;
}
else if (str[j] != data[j])
{
incorrectWords++;
}
}
label1.Text += correctWords.ToString();
label6.Text += incorrectWords.ToString();
int accuracy = (correctWords * 100 / data.Length);
label3.Text += accuracy.ToString() + "%";
label5.Text += (correctWords + incorrectWords).ToString();
textBox1.ReadOnly = true;
timer1.Enabled = false;
textBox1.Enabled = false;
label8.Text = "0";
label1.Focus();
}
}
}
VB.Net
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Namespace _925078_TypingSpeed
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private data As String()
Private startTime As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs)
textBox2.Text = "When the test first starts up, it will present you with a choice of lesson and time. If you are in a hurry, choose the 1 Minute Timed Typing Test. For a more accurate assessment, choose the 5 Minute Test. Lessons 26-35 are the classic story lessons and can make a better overall assessment by typing natural sentences. All the other lessons are available, so if you want to see what your wpm is on the home row keys, or your speed in the 10-key you can. New lessons 38 through 40 include Spanish, French, Russian, Hindi and German words."
data = textBox2.Text.Split(" "C)
textBox2.[ReadOnly] = True
label8.Text = "60"
End Sub
Private Sub timer1_Tick(sender As Object, e As EventArgs)
startTime = startTime + 1000
label8.Text = Convert.ToString(Convert.ToInt32(label8.Text) - 1)
If startTime >= 60000 Then
CalculateAccuracy()
End If
End Sub
Private Sub textBox1_TextChanged(sender As Object, e As EventArgs)
timer1.Enabled = True
If startTime >= 60000 Then
CalculateAccuracy()
End If
End Sub
Private Sub CalculateAccuracy()
Dim correctWords As Integer = 0
Dim incorrectWords As Integer = 0
Dim output As String = textBox1.Text
Dim str As String() = output.Split(" "C)
For j As Integer = 0 To str.Length - 1
If str(j) = data(j) Then
correctWords += 1
ElseIf str(j) <> data(j) Then
incorrectWords += 1
End If
Next
label1.Text += correctWords.ToString()
label6.Text += incorrectWords.ToString()
Dim accuracy As Integer = (correctWords * 100 / data.Length)
label3.Text += accuracy.ToString() + "%"
label5.Text += (correctWords + incorrectWords).ToString()
textBox1.[ReadOnly] = True
timer1.Enabled = False
textBox1.Enabled = False
label8.Text = "0"
label1.Focus()
End Sub
End Class
End Namespace