Plurals

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I have a function that I am trying to write.
If CNT =1 then check ReportCatName, if it has an "s" at the end. If so then
remove it, else do nothing.
If CNT >1 then check ReportCatName, it it has an "s" at the end, do nothing.
If it doesn't have an "s" then add an "s".

This isn't doing it for me. I think the problem is where the "s" is to be
removed.
ReportCatName is a field in a table and has words like Appetizers, Entrees,
etc.

Thanks
DS

Public Function MANY(ReportCatName) As String
Dim CNT As Integer
If CNT = 1 Then
If right(ReportCatName, 1) = "s" Then
ReportCatName = right(ReportCatName, -1)
ElseIf right(ReportCatName, 1) <> "s" Then
ReportCatName
End If
ElseIf CNT > 1 Then
If right(ReportCatName, 1) = "s" Then
ReportCatName
ElseIf right(ReportCatName, 1) <> "s" Then
ReportCatName = ReportCatName & "s
End If
End If
End Function
 
Hi DS,
Try in this way

Public Function MANY(ReportCatName) As String
Dim CNT As Integer
If CNT = 1 Then
If right(ReportCatName, 1) = "s" Then
ReportCatName = left(ReportCatName,len(ReportCatName) -1)
ElseIf right(ReportCatName, 1) <> "s" Then
ReportCatName
End If
ElseIf CNT > 1 Then
If right(ReportCatName, 1) = "s" Then
ReportCatName
ElseIf right(ReportCatName, 1) <> "s" Then
ReportCatName = ReportCatName & "s"
End If
End If
End Function

HTH Paolo
 
Your function isn't returning anything. Also, you have dimmed CNT in your
function, so it will not see the other CNT. When run, CNT will always be 0.
You need to also pass the value of CNT from where you are calling the
function. Also, you don't allow for CNT bein 0 or less than 0

Public Function MANY(ReportCatName, CNT As Integer) As String
If CNT = 1 Then
If right(ReportCatName, 1) = "s" Then
MANY = Left(ReportCatName, Len(ReportCatName -1))
Else
MANY = ReportCatName
End If
ElseIf CNT > 1 Then
If right(ReportCatName, 1) = "s" Then
MANY = ReportCatName
Else
MANY = ReportCatName & "s"
End If
End If
End Function
 
Back
Top