Advertisement
Java_Volume1 String Manipulation #89469

Plural Check (extremely simple, very useful)

I hope I'm not the only person who wants to cringe every time I see something like "You have been online for 1 minutes." 1 minutes?? I see this kind of thing everywhere; here on PSC, even. It looks very unprofessional to me, and it's so easy to fix! That's why I listed this code as beginner level. Hopefully, Planet Source Code will implement this code and I won't have to see that I got an excellent vote from "1 users." ;-) I would like to hear any comments you have about this code. Also, please click to see my other submissions to PSC. My latest program, Music Maker is nearing the top of the Code of the Month list. If I can get a few more votes it would really help me out! :-) Thanks for looking!

AI

Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Codice sorgente
original-source
'add a command button and a textbox to your form
Option Explicit
Function PluralCheck(Num, Singular As String, Plural As String) As String
Dim NumString As String
NumString = Trim(Str(Num)) & " "
If Num = 1 Then
 PluralCheck = NumString & Singular
Else
 PluralCheck = NumString & Plural
End If
End Function
Private Sub Command1_Click()
Dim N As Integer
N = Val(Text1.Text)
MsgBox "Cats have " & PluralCheck(N, "life", "lives")
End Sub
Commenti originali (3)
Recuperato da Wayback Machine