Jump to content

Characters & Words per minute or second


Jex
 Share

Recommended Posts

Posted Image

#include <GUIConstants.au3>
#include <GuiStatusBar.au3>

Global $Exit = 0, $aParts[2] = [300, 150], $Read[3], $Compare[3]
$Form = GUICreate("Characters & Words per minute or second", 483, 495, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 465, 209, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL))
$Edit2 = GUICtrlCreateEdit("", 8, 224, 465, 209, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL))
GUICtrlSetState($Edit2, $GUI_DISABLE)
GUICtrlSetData($Edit1, "")
$Button = GUICtrlCreateButton("Start", 8, 440, 467, 25, 0)
$hStatus = _GUICtrlStatusBar_Create($Form, $aParts)
_GUICtrlStatusBar_SetMinHeight($hStatus, 20)
$Progress = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_SMOOTH)
$hProgress = GUICtrlGetHandle($Progress)
_GUICtrlStatusBar_EmbedControl($hStatus, 1, $hProgress)
_SendMessage($hProgress, $PBM_SETMARQUEE, True, 200)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            $Wrong = 0
            GUICtrlSetState($Edit1, $GUI_DISABLE)
            GUICtrlSetData($Edit2, "")
            GUICtrlSetData($Button, "Stop")
            $Len = StringLen(GUICtrlRead($Edit1))
            $Words = StringSplit(GUICtrlRead($Edit1), " ", 1)
            Sleep(500)
            GUICtrlSetState($Edit2, BitOR($GUI_FOCUS, $GUI_ENABLE))
            $Timer = TimerInit()
            Do
                $msg2 = GUIGetMsg()
                If $msg2 = $Button Then
                    $Exit = 1
                    ExitLoop
                ElseIf $msg2 = $GUI_EVENT_CLOSE Then
                    Exit
                EndIf
                $Len2 = StringLen(GUICtrlRead($Edit2))
                $Perc = Round(($Len2 / $Len) * 100, 0)
                _GUICtrlStatusBar_SetText($hStatus, "Letters count : " & $Len2 & " ( " & $Perc & "% )")
                GUICtrlSetData($Progress, $Perc)
            Until $Len2 >= $Len
            If $Exit = 0 Then
                $TimerDiff = Round(TimerDiff($Timer) / 1000, 2)
                $LPS = Round($Len / $TimerDiff, 2)
                $LPM = Round($LPS * 60, 2)
                $WPS = Round((UBound($Words) - 1) / $TimerDiff, 2)
                $WPM = Round($WPS * 60, 2)
                $Read[1] = GUICtrlRead($Edit1)
                $Read[2] = GUICtrlRead($Edit2)
                For $i = 1 To $Len
                    For $z = 1 To 2
                        $Compare[$z] = StringLeft($Read[$z], $i)
                        If $i <> 1 Then $Compare[$z] = StringTrimLeft($Read[$z], $i - 1)
                    Next
                    If $Compare[1] <> $Compare[2] Then $Wrong += 1
                Next
                MsgBox("", "Result", "Completed in " & $TimerDiff & " second." & @CRLF & "Total Letters : " & $Len & @CRLF & _
                "Total Words : " & UBound($Words) - 1 & @CRLF & "CPS : " & $LPS & @CRLF & "CPM : " & $LPM & @CRLF & "WPS : " & $WPS & @CRLF & "WPM : " & $WPM & @CRLF & _
                "Wrong letter count : " & $Wrong & " ( " & Round(($Wrong / $Len) * 100, 0) & "% )")
            EndIf
            GUICtrlSetState($Edit1, $GUI_ENABLE)
            GUICtrlSetState($Edit2, $GUI_DISABLE)
            GUICtrlSetData($Button, "Start")
            GUICtrlSetData($Progress, 0)
            _GUICtrlStatusBar_SetText($hStatus, "")
            $Exit = 0
    EndSwitch
WEnd
Edited by Jex
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...