Re: Surprise in StrConv using vbProperCase

From: Gary Schuldt (garyschuldt_at_comcast.net)
Date: 11/09/04


Date: Tue, 9 Nov 2004 11:00:06 -0800

Thanks, Ken,

(Before posting, I searched for StrConv and proper case and vbProperCase and
got no hits on any of them.)

Your code will capitalize the first letter of a string. The strings I have
could consist of multiple words (they are cultivar names of plants, such as
MacTavish's Sky Pencil), so the specs for StrConv using vbProperCase match
what I need. (Unfortunately, it doesn't work as advertised.)

Because the cultivar often includes the cultivator's name, you could
conceivably have Meyers-Briggs Delight.

The Int'l Rules for Botanical Nomenclature say each word in the cultivar
name must be capitalized. There is no rule to cover the case when hyphens
are present, so I will just have to trust the user to type the correct name
in those cases.

I'm thinking of writing a StrCapitalize that will:

    1. Do what your CapFirstLetter below does, but for each "word" in the
string;
    2. Assume/use a blank as a delimiter for words;
    3. Squeeze out superfluous blanks (since they are so hard to detect
visually).

My pseudocode would be something like:

    1. Use Split(string into array of words using blank as delimiter);
    2. (I'm not what sure Split does when it encounters two consecutive
delimiters; does it yield an (extra) array element with a value of a
zero-length string?)
    3. Use your CapFirstLetter function on each element of the array
    4. Use Join(the array back into a string using blank as delimiter).

I would display the result and tell the user if it's not yet correct (like
intracaps needed for MacDonald and O'Hara and Barr-Mason) they can correct
it themselves.

What do you think?

Gary

"Ken Snell [MVP]" <kthsneisllis9@ncoomcastt.renaetl> wrote in message
news:u793UemxEHA.2348@TK2MSFTNGP12.phx.gbl...
> Try this (the behavior you note for StrConv is a commonly discussed issue
> here in the newsgroups):
>
> Public Function CapFirstLetter(strString As String) As String
> Dim strLetter As String
> strLetter = Left(strString, 1)
> Select Case Asc(strLetter)
> Case 97 To 122
> strLetter = Chr(Asc(strLetter) - 32)
> End Select
> CapFirstLetter = strLetter & Mid(strString, 2)
> End Function
> --
>
> Ken Snell
> <MS ACCESS MVP>
>
>
>
> "Gary Schuldt" <garyschuldt@comcast.net> wrote in message
> news:%23Jk0epjxEHA.1452@TK2MSFTNGP11.phx.gbl...
> > VBA Help says using the vbProperCase option in the StrConv function
> converts
> > the first letter of every word to uppercase.
> >
> > The surprise is that it converts all other characters to lower case!
> >
> > This is an *unpleasant* surprise in my application, because it changes
> > "O'Malley" to "O'malley", which I don't want.
> >
> > I just want a function to capitalize the first letter of each word and
> leave
> > the other letters alone. Anyone know of such a function so I don't have
> to
> > code it myself?
> >
> > Gary
> >
> >
>
>



Relevant Pages

  • Re: Advanced HTML DOM Issue
    ... I'm sorry, I wasn't explicit enough, I meant to say capitalize the ... the first letter of words and un-cap the rest, ... whole string causes the field to forget where the cursor is ... ...
    (alt.html)
  • Re: Capitalize first letter in sentence
    ... PROPER will capitalize the first letter of each word, ... capitalizes just the first word of the string. ... This leaves the rest of the string unchanged and capitalises the first ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Surprise in StrConv using vbProperCase
    ... Try this (the behavior you note for StrConv is a commonly discussed issue ... Public Function CapFirstLetter(strString As String) As String ... Dim strLetter As String ... > the first letter of every word to uppercase. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Need string for capitalization
    ... >> I'm trying to capitalize the first letter of a field but the string I am ... > In a report control Source: ...
    (microsoft.public.access.gettingstarted)
  • Re: [string totitle "ab cd ef"] does not output "Ab Cd Ef" but instead"Ab
    ... Will Duquette wrote: ... > capitalizing a string, sometimes you want to capitalize just the first ... and sometimes you want to capitalize the first letter of every ...
    (comp.lang.tcl)