Re: Surprise in StrConv using vbProperCase
From: Ken Snell [MVP] (kthsneisllis9_at_ncoomcastt.renaetl)
Date: 11/09/04
- Next message: Ken Snell [MVP]: "Re: Date format / runtime"
- Previous message: Brian: "Date format / runtime"
- In reply to: Gary Schuldt: "Re: Surprise in StrConv using vbProperCase"
- Next in thread: Gary Schuldt: "Re: Surprise in StrConv using vbProperCase"
- Reply: Gary Schuldt: "Re: Surprise in StrConv using vbProperCase"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 9 Nov 2004 16:04:15 -0500
Sorry, Gary... my minds' eye narrowed its vision field too much when I put
that function together. Wasn't thinking about multiple words being handled
that way. But I think Dirk has posted a more comprehensive function for you.
--
Ken Snell
<MS ACCESS MVP>
"Gary Schuldt" <garyschuldt@comcast.net> wrote in message
news:uCqdl6oxEHA.3572@TK2MSFTNGP10.phx.gbl...
> 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
> > >
> > >
> >
> >
>
>
- Next message: Ken Snell [MVP]: "Re: Date format / runtime"
- Previous message: Brian: "Date format / runtime"
- In reply to: Gary Schuldt: "Re: Surprise in StrConv using vbProperCase"
- Next in thread: Gary Schuldt: "Re: Surprise in StrConv using vbProperCase"
- Reply: Gary Schuldt: "Re: Surprise in StrConv using vbProperCase"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|