Plural Strings in Status Messages
I have a lot of pet peeves. One involves status update messages. When processing a bunch of documents (especially when tying up the Notes client), I like to print out status update messages. But I hate seeing "Copied 1 documents so far" (plural with the number 1) or "Copied 10 document so far" (singular with the number 10).However, in LotusScript, you need multiple lines to print out the correct case, like in this example:
If count = 1 Then
Print "Copied 1 document so far"
Else
Print "Copied " & CStr(count) & " documents so far"
End If
In JavaScript, you can get away with doing it in one line through the in-line comparison:
"Copied " + count + " document" + (count == 1 ? "" : "s") + " so far"
(Yes, not completely correct syntax for JavaScript, but you get the idea).
To make things easier and satify my OCD tendencies, I wrote a quick little function to "pluralize" status message words:
Function Plural(num As Integer) As String
On Error GoTo BubbleError
' Add "s" to the string if num is not equal to 1
If num = 1 Then Plural = "" Else Plural = "s"
Exit Function
BubbleError:
Error Err, Error$ & Chr$(10) & "in function " & Getthreadinfo(1) & ", line " & Cstr(Erl)
End Function
So, now my original code can look like this:
Print "Copied " & CStr(count) & " document" & Plural(count) & " so far"
What about "es" (as in "matches")? Well, I wrote a second function, I call this one Plurales (which isn't a word, but lets me know what the purpose is).
Function Plurales(num As Integer) As String
On Error GoTo BubbleError
' Add "es" to the string if num is not equal to 1
If num = 1 Then Plurales = "" Else Plurales = "es"
Exit Function
BubbleError:
Error Err, Error$ & Chr$(10) & "in function " & Getthreadinfo(1) & ", line " & Cstr(Erl)
End Function