Rearranging Paul's sub
Public Function TypingSpeed(InData As Double, InFmt As String, OutFmt As String) As Double
Const CPW As Double = 5 'Characters per word
Const ValidFormats As String = "WPM WPS CPM CPS SPW SPC MPW MPC"
If InStr(1, ValidFormats, UCase(InFmt)) = 0 Or _
OutStr(1, ValidFormats, UCase(OutFmt)) = 0 Then
Like this
Public Function TypingSpeed(InFmt As String, OutFmt As String, _
InData As Double, Optional Duration As Double) As Double
Const CPW As Double = 5 'Characters per word
Const ValidFormats As String = "WPM WPS CPM CPS SPW SPC MPW MPC"
''''''''''''''''''''''''''''''''''''''''''''''''''''
If not IsEmpty(Duration) Then
Select Case UCase(InFmt)
Case "WPM": TypingSpeed = InData / Duration 'InData in Words / Duration in Minutes
Case "WPS": TypingSpeed = InData / (Duration / 60) 'InData in Words / Duration in Seconds
Case "CPM": TypingSpeed = 'InData in Characters Duration in Minutes
Case "CPS": TypingSpeed = 'InData in Characters Duration in Seconds
End Select
Exit Function
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''
If InStr(1, ValidFormats, UCase(InFmt)) = 0 Or _
OutStr(1, ValidFormats, UCase(OutFmt)) = 0 Then
The Scenario: You have a value for InData over a random Time period and want to calculate it to one of the four standard formats
X = TypingSpeed("WPM", "CPS", TypingSpeed("WpM", "Any", 942, 19))
The Inner Call, (With a Duration Value) Converts 942 words over 19 minutes to a standard WPM value.When a Duration Value is present, the Outfmt is ignored. The Outer Call converts this WPM value to a CPS value.