PC Review


Reply
Thread Tools Rate Thread

How Can i create a function that returns the case of a word

 
 
DZ
Guest
Posts: n/a
 
      1st Jul 2004
Greeting

How Can i create a function that returns the case of a
word.

Example:

Function ReturnCaseOfWord(strWord As String) As String

End Function

I want the function to return a string that is the case of
the word: "Upper", "Lower" or "Proper".

Thanks for any help
DZ
 
Reply With Quote
 
 
 
 
Chris Nebinger
Guest
Posts: n/a
 
      1st Jul 2004
The key is to use Option Compare Binary:

Option Compare Binary
Option Explicit
Function ReturnCaseOfWord(strWord As String) As String
Select Case strWord
Case UCase(strWord)
ReturnCaseOfWord = "Upper"
Case LCase(strWord)
ReturnCaseOfWord = "Lower"
Case StrConv(strWord, vbProperCase)
ReturnCaseOfWord = "Proper"
Case Else
ReturnCaseOfWord = "Other"
End Select
End Function


Chris Nebinger

>-----Original Message-----
>Greeting
>
>How Can i create a function that returns the case of a
>word.
>
>Example:
>
>Function ReturnCaseOfWord(strWord As String) As String
>
>End Function
>
>I want the function to return a string that is the case

of
>the word: "Upper", "Lower" or "Proper".
>
>Thanks for any help
>DZ
>.
>

 
Reply With Quote
 
John Nurick
Guest
Posts: n/a
 
      1st Jul 2004
Hi DZ,

This is fairly simple if you're only interested in the 26 letters of the
English alphabet.

Something like this:

Dim A As Long
Dim j As Long
Dim blFirstUpper As Boolean
Dim blRestUpper As Boolean
Dim blRestLower As Boolean
Dim blNotAWord As Boolean
Dim S As String

'First character
A = Asc(Left(strWord,1))
If A >= 65 And A <= 90 Then
blFirstUpper = True
ElseIf A >= 97 And A <= 122 Then
blFirstUpper = False
Else
blNotAWord = True
End If

'Remainder
blRestUpper = True
blRestLower = True
For j = 2 to Len(strWord)
A = Asc(Mid(strWord(j, 1))
If A >=65 And A <= 90 Then
blRestLower = False
ElseIf A < 97 Or A > 122 Then
blNotAWord = True
End If
If A >= 97 And A <= 122 Then
blRestUpper = False
ElseIf A < 65 Or A > 90 Then
blNotAWord = True
End IF
Next

'Work it out
If blNotAWord Then
S = "Not a word"
Else
'a series of logical tests, e.g.
If blFirstUpper And blRestLower Then S = "Proper"
If blFirstUpper And blRestUpper Then S = "Upper"
If Not blFirstUpper And BlRestLower Then S = "Lower"
... otherwise S = "Mixed"
End If

If however you need to cope with accented characters, non-western
scripts and the like it gets quite complicated!



On Thu, 1 Jul 2004 11:51:25 -0700, "DZ" <(E-Mail Removed)> wrote:

>Greeting
>
>How Can i create a function that returns the case of a
>word.
>
>Example:
>
>Function ReturnCaseOfWord(strWord As String) As String
>
>End Function
>
>I want the function to return a string that is the case of
>the word: "Upper", "Lower" or "Proper".
>
>Thanks for any help
>DZ


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Reply With Quote
 
John Nurick
Guest
Posts: n/a
 
      1st Jul 2004
I've just had a neater idea, perhaps.

Apply strConv() to your word with various arguments, and see which
argument doesn't change the word.


On Thu, 1 Jul 2004 11:51:25 -0700, "DZ" <(E-Mail Removed)> wrote:

>Greeting
>
>How Can i create a function that returns the case of a
>word.
>
>Example:
>
>Function ReturnCaseOfWord(strWord As String) As String
>
>End Function
>
>I want the function to return a string that is the case of
>the word: "Upper", "Lower" or "Proper".
>
>Thanks for any help
>DZ


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Reply With Quote
 
DZ
Guest
Posts: n/a
 
      1st Jul 2004
Thank you very much.


 
Reply With Quote
 
John Nurick
Guest
Posts: n/a
 
      2nd Jul 2004
Hi Chris,

Much neater than my solution.

I tried it out with Central European and Greek characters (on a form, to
avoid Unicode problems in the Immediate pane) and it fails on these,
which must stem from the way the VBA string functions handle Unicode
(Windows 2000/Access 2002 at this end). With luck these will eventually
be fixed<g>.

On Thu, 1 Jul 2004 13:45:28 -0700, "Chris Nebinger"
<(E-Mail Removed)> wrote:

>The key is to use Option Compare Binary:
>
>Option Compare Binary
>Option Explicit
>Function ReturnCaseOfWord(strWord As String) As String
> Select Case strWord
> Case UCase(strWord)
> ReturnCaseOfWord = "Upper"
> Case LCase(strWord)
> ReturnCaseOfWord = "Lower"
> Case StrConv(strWord, vbProperCase)
> ReturnCaseOfWord = "Proper"
> Case Else
> ReturnCaseOfWord = "Other"
> End Select
>End Function
>
>
>Chris Nebinger
>
>>-----Original Message-----
>>Greeting
>>
>>How Can i create a function that returns the case of a
>>word.
>>
>>Example:
>>
>>Function ReturnCaseOfWord(strWord As String) As String
>>
>>End Function
>>
>>I want the function to return a string that is the case

>of
>>the word: "Upper", "Lower" or "Proper".
>>
>>Thanks for any help
>>DZ
>>.
>>


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Reply With Quote
 
Chris Nebinger
Guest
Posts: n/a
 
      2nd Jul 2004
I'm one of the arrogant American's who thinks the world
does not exist outside of the US.


Actually, I've never had to work with Unicode, so I don't
have any advice for that.


Chris Nebinger


>-----Original Message-----
>Hi Chris,
>
>Much neater than my solution.
>
>I tried it out with Central European and Greek characters

(on a form, to
>avoid Unicode problems in the Immediate pane) and it

fails on these,
>which must stem from the way the VBA string functions

handle Unicode
>(Windows 2000/Access 2002 at this end). With luck these

will eventually
>be fixed<g>.
>
>On Thu, 1 Jul 2004 13:45:28 -0700, "Chris Nebinger"
><(E-Mail Removed)> wrote:
>
>>The key is to use Option Compare Binary:
>>
>>Option Compare Binary
>>Option Explicit
>>Function ReturnCaseOfWord(strWord As String) As String
>> Select Case strWord
>> Case UCase(strWord)
>> ReturnCaseOfWord = "Upper"
>> Case LCase(strWord)
>> ReturnCaseOfWord = "Lower"
>> Case StrConv(strWord, vbProperCase)
>> ReturnCaseOfWord = "Proper"
>> Case Else
>> ReturnCaseOfWord = "Other"
>> End Select
>>End Function
>>
>>
>>Chris Nebinger
>>
>>>-----Original Message-----
>>>Greeting
>>>
>>>How Can i create a function that returns the case of a
>>>word.
>>>
>>>Example:
>>>
>>>Function ReturnCaseOfWord(strWord As String) As String
>>>
>>>End Function
>>>
>>>I want the function to return a string that is the case

>>of
>>>the word: "Upper", "Lower" or "Proper".
>>>
>>>Thanks for any help
>>>DZ
>>>.
>>>

>
>--
>John Nurick [Microsoft Access MVP]
>
>Please respond in the newgroup and not by email.
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search function in Word 2007 help returns only XML James Microsoft Word Document Management 1 21st Sep 2009 08:30 PM
Create Function which returns an Array ExcelMonkey Microsoft Excel Programming 8 24th Jun 2008 07:29 PM
Create VBA function that returns many values gkk-vba Microsoft Excel Programming 2 19th Jan 2008 12:10 AM
ADD Change Case function from Word to Excel =?Utf-8?B?Q2Fyb2x5biBF?= Microsoft Excel Worksheet Functions 2 7th Aug 2006 08:03 PM
Create Select Case Function =?Utf-8?B?Q2F0YWxpbg==?= Microsoft Excel Programming 6 27th Mar 2006 10:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:36 PM.