| Author |
Case Determination
|
|
| JustLearning@aol.com 2005-12-14, 7:55 am |
| Does anyone know a simple subroutine to determine if a word is
Uppercase, Lowercase or Propercase?
| |
| Schmidt 2005-12-14, 7:55 am |
|
<JustLearning@aol.com> schrieb im Newsbeitrag
news:ep10q1lljtnd71n10vlijc7qqdkli0fg6t@
4ax.com...
> Does anyone know a simple subroutine to determine if a word is
> Uppercase, Lowercase or Propercase?
If S = StrConv(S, vbProperCase) then
...
Works also with vbLowerCase and vbUpperCase.
Olaf
| |
| George Bashore 2005-12-14, 6:57 pm |
| JustLearning try this
1 textbox
1 command button
this code
Option Explicit
Private Sub Command1_Click()
Dim myStr As String
myStr = Text1.Text
Select Case myStr
Case UCase(myStr)
MsgBox myStr & " is " & "Uppercase"
Case LCase(myStr)
MsgBox myStr & " is " & "Lowercase"
Case Else
MsgBox myStr & " is " & "Propercase"
End Select
End Sub
Private Sub Form_Load()
Command1.Caption = "Check Case"
End Sub
<JustLearning@aol.com> wrote in message
news:ep10q1lljtnd71n10vlijc7qqdkli0fg6t@
4ax.com...
> Does anyone know a simple subroutine to determine if a word is
> Uppercase, Lowercase or Propercase?
| |
| Dmitriy Antonov 2005-12-14, 6:57 pm |
|
"George Bashore" <gbashore@bcpl.net> wrote in message
news:uqmAfUMAGHA.312@TK2MSFTNGP09.phx.gbl...
> JustLearning try this
> 1 textbox
> 1 command button
> this code
>
> Option Explicit
>
> Private Sub Command1_Click()
> Dim myStr As String
> myStr = Text1.Text
> Select Case myStr
> Case UCase(myStr)
> MsgBox myStr & " is " & "Uppercase"
> Case LCase(myStr)
> MsgBox myStr & " is " & "Lowercase"
> Case Else
> MsgBox myStr & " is " & "Propercase"
> End Select
> End Sub
>
> Private Sub Form_Load()
> Command1.Caption = "Check Case"
> End Sub
>
>
>
> <JustLearning@aol.com> wrote in message
> news:ep10q1lljtnd71n10vlijc7qqdkli0fg6t@
4ax.com...
>
..
This may produce wrong result -you can't conclude that the word is in
Propercase if it is neither Lowercase nor Uppercase.
Dmitriy.
| |
| Bob Butler 2005-12-14, 6:57 pm |
| "George Bashore" <gbashore@bcpl.net> wrote in message
news:uqmAfUMAGHA.312@TK2MSFTNGP09.phx.gbl
> JustLearning try this
> 1 textbox
> 1 command button
> this code
>
> Option Explicit
>
> Private Sub Command1_Click()
> Dim myStr As String
> myStr = Text1.Text
> Select Case myStr
> Case UCase(myStr)
> MsgBox myStr & " is " & "Uppercase"
> Case LCase(myStr)
> MsgBox myStr & " is " & "Lowercase"
> Case Else
> MsgBox myStr & " is " & "Propercase"
> End Select
> End Sub
>
> Private Sub Form_Load()
> Command1.Caption = "Check Case"
> End Sub
What if the textbox contains "aBc" or "123xyz" or "!@#" ?
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
| George Bashore 2005-12-14, 6:57 pm |
| Is eBay a propercase word?
I wasn't sure how to handle that.
try this code
Option Explicit
Private Sub Command1_Click()
Dim myStr As String
myStr = Text1.Text
Select Case myStr
Case UCase(myStr)
MsgBox myStr & " is " & "Uppercase"
Case LCase(myStr)
MsgBox myStr & " is " & "Lowercase"
Case StrConv(myStr, vbProperCase)
MsgBox myStr & " is " & "Propercase"
Case Else
MsgBox myStr & " is " & "Is not UCase, LCase or ProperCase."
End Select
End Sub
Private Sub Form_Load()
Command1.Caption = "Check Case"
End Sub
"Dmitriy Antonov" <antonovdima@netzero.net_NOT_FOR_SPAM> wrote in message
news:%23bOJxfMAGHA.1408@TK2MSFTNGP15.phx.gbl...
>
> "George Bashore" <gbashore@bcpl.net> wrote in message
> news:uqmAfUMAGHA.312@TK2MSFTNGP09.phx.gbl...
>
> .
> This may produce wrong result -you can't conclude that the word is in
> Propercase if it is neither Lowercase nor Uppercase.
>
> Dmitriy.
>
| |
| Ken Halter 2005-12-14, 6:57 pm |
| "George Bashore" <gbashore@bcpl.net> wrote in message
news:%23fBlXCOAGHA.3936@TK2MSFTNGP12.phx.gbl...
> Is eBay a propercase word?
No
'===
Private Sub Form_Load()
Debug.Print StrConv("eBay", vbProperCase) 'Shows Ebay
End Sub
'===
> I wasn't sure how to handle that.
Add another test called "Mixed Case". Pretty much, anything that's (not all
upper), (not all lower) and (not 'Proper') can be considered "mixed"
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
| |
| George Bashore 2005-12-14, 6:57 pm |
| Bob
The OP ask about a word. What word has 123 or !@# in it?
I was playing around with these numbers and characters and the code will
disreguard the numbers and characters with small letters in the textbox.
Without letters they will show UCase but if you put in small letters they
will show LCase.
If you use !@#Bob it will show "Is not UCase, LCase or ProperCase"
If you use !@#bob it will show LCase.
I changed the code to but now I can't use eBay.
George
Option Explicit
Private Sub Command1_Click()
Dim myStr As String
myStr = Text1.Text
Select Case myStr
Case UCase(myStr)
MsgBox myStr & " is " & "Uppercase"
Case LCase(myStr)
MsgBox myStr & " is " & "Lowercase"
Case StrConv(myStr, vbProperCase)
MsgBox myStr & " is " & "Propercase"
Case Else
MsgBox myStr & " is " & "Is not UCase, LCase or ProperCase"
End Select
End Sub
Private Sub Form_Load()
Command1.Caption = "Check Case"
End Sub
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:uTYX5gMAGHA.3872@TK2MSFTNGP12.phx.gbl...
> "George Bashore" <gbashore@bcpl.net> wrote in message
> news:uqmAfUMAGHA.312@TK2MSFTNGP09.phx.gbl
>
> What if the textbox contains "aBc" or "123xyz" or "!@#" ?
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
| |
| Bob Butler 2005-12-14, 6:57 pm |
| "George Bashore" <gbashore@bcpl.net> wrote in message
news:erYI5OOAGHA.3984@TK2MSFTNGP14.phx.gbl
> Bob
> The OP ask about a word. What word has 123 or !@# in it?
I use !@# a lot, especially at work! <g>
I was just illustrating that the original test you proposed was claiming
'proper case' when that might not be true. I'm also not so sure that the
use of the term "word" in the OP can be limited to actual "words". The eBay
example that was given later was probably better but it depends on where the
OP is getting the "words" from.
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
| George Bashore 2005-12-14, 6:57 pm |
| Ken
Ebay is not correct. It's eBay.
Hows this for Mixed Case
Option Explicit
Private Sub Command1_Click()
Dim myStr As String
myStr = Text1.Text
Select Case myStr
Case UCase(myStr)
MsgBox myStr & " is " & "Uppercase"
Case LCase(myStr)
MsgBox myStr & " is " & "Lowercase"
Case StrConv(myStr, vbProperCase)
MsgBox myStr & " is " & "Propercase"
Case Else
MsgBox myStr & " is " & "Is not UCase, LCase or ProperCase" & _
vbNewLine & "It must be Mixed Case."
End Select
End Sub
Private Sub Form_Load()
Command1.Caption = "Check Case"
End Sub
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:ODXZVOOAGHA.2040@TK2MSFTNGP14.phx.gbl...
> "George Bashore" <gbashore@bcpl.net> wrote in message
> news:%23fBlXCOAGHA.3936@TK2MSFTNGP12.phx.gbl...
>
> No
> '===
> Private Sub Form_Load()
> Debug.Print StrConv("eBay", vbProperCase) 'Shows Ebay
> End Sub
> '===
>
>
> Add another test called "Mixed Case". Pretty much, anything that's (not
> all upper), (not all lower) and (not 'Proper') can be considered "mixed"
>
>
> --
> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
> DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
> Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
>
| |
| JustLearning@aol.com 2005-12-14, 6:57 pm |
| After the first reply I did not check back and did not notice all
these additional comments. For my needs if something is not uppercase
or lowercase and has a captial as the first letter I will take a
proeprcase so I had written this as"my" solution. However, you raise
an interesting question with eBay. and numbers . so I guess it is not
such an easy question after all
Private Sub Command1_Click()
If Text2.Text = StrConv(Text1.Text, vbProperCase) Then
MsgBox "vbProperCase"
ElseIf Text2.Text = StrConv(Text1.Text, vbLowerCase) Then
MsgBox "vbLowerCase"
ElseIf Text2.Text = StrConv(Text1.Text, vbUpperCase) Then
MsgBox "vbUpperCase"
Else
If Asc(Left(Text1.Text, 1)) >= 65 And Asc(Left(Text1.Text, 1))
<= 90 Then
MsgBox "Do Not Know But Will Treat as vbProperCase"
Else
MsgBox "Do Not Know But Will Trart as vbLowerCase"
End If
End If
End Sub
| |
| Dmitriy Antonov 2005-12-14, 6:57 pm |
|
<JustLearning@aol.com> wrote in message
news:ah11q15nb8aj3cvt17lnr43rjqcd2uile6@
4ax.com...
> After the first reply I did not check back and did not notice all
> these additional comments. For my needs if something is not uppercase
> or lowercase and has a captial as the first letter I will take a
> proeprcase so I had written this as"my" solution. However, you raise
> an interesting question with eBay. and numbers . so I guess it is not
> such an easy question after all
>
>
> Private Sub Command1_Click()
> If Text2.Text = StrConv(Text1.Text, vbProperCase) Then
> MsgBox "vbProperCase"
> ElseIf Text2.Text = StrConv(Text1.Text, vbLowerCase) Then
> MsgBox "vbLowerCase"
> ElseIf Text2.Text = StrConv(Text1.Text, vbUpperCase) Then
> MsgBox "vbUpperCase"
> Else
> If Asc(Left(Text1.Text, 1)) >= 65 And Asc(Left(Text1.Text, 1))
> <= 90 Then
> MsgBox "Do Not Know But Will Treat as vbProperCase"
> Else
> MsgBox "Do Not Know But Will Trart as vbLowerCase"
> End If
> End If
> End Sub
>
Isn't it mistake - you use Text2 and Text1 in the same statements. And for
better performance and clarity I would use local variable instead of
Text1.Text
Dmitriy.
| |
| JustLearning@aol.com 2005-12-14, 6:57 pm |
| Oops Thet are all text1.txt it was a typo
On Wed, 14 Dec 2005 16:36:51 -0500, "Dmitriy Antonov"
<antonovdima@netzero.net_NOT_FOR_SPAM> wrote:
>
><JustLearning@aol.com> wrote in message
> news:ah11q15nb8aj3cvt17lnr43rjqcd2uile6@
4ax.com...
>
>Isn't it mistake - you use Text2 and Text1 in the same statements. And for
>better performance and clarity I would use local variable instead of
>Text1.Text
>
>Dmitriy.
>
| |
| JustLearning@aol.com 2005-12-14, 6:57 pm |
| As was Trart
On Wed, 14 Dec 2005 16:36:51 -0500, "Dmitriy Antonov"
<antonovdima@netzero.net_NOT_FOR_SPAM> wrote:
>
><JustLearning@aol.com> wrote in message
> news:ah11q15nb8aj3cvt17lnr43rjqcd2uile6@
4ax.com...
>
>Isn't it mistake - you use Text2 and Text1 in the same statements. And for
>better performance and clarity I would use local variable instead of
>Text1.Text
>
>Dmitriy.
>
| |
|
|
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:uoLB1SOAGHA.3584@TK2MSFTNGP14.phx.gbl...
> "George Bashore" <gbashore@bcpl.net> wrote in message
> news:erYI5OOAGHA.3984@TK2MSFTNGP14.phx.gbl
>
> I use !@# a lot, especially at work! <g>
>
> I was just illustrating that the original test you proposed was claiming
> 'proper case' when that might not be true. I'm also not so sure that the
> use of the term "word" in the OP can be limited to actual "words". The
eBay
> example that was given later was probably better but it depends on where
the
> OP is getting the "words" from.
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
Also, nobody has mentioned the ugly situation with "O'Brian". Which not only
isn't *any* case - it tends to trash SQL. <g>
-ralph
| |
| Rick Rothstein [MVP - Visual Basic] 2005-12-14, 9:55 pm |
| > After the first reply I did not check back and did not notice all
> these additional comments. For my needs if something is not uppercase
> or lowercase and has a captial as the first letter I will take a
> proeprcase
Here is another method that has not been mentioned yet...
Dim myWord As String
myWord = Text1.Text
If Not myWord Like "*[!A-Z]*" Then
Debug.Print "Text is all upper case"
ElseIf Not myWord Like "*[!a-z]*" Then
Debug.Print "Text is all lower case"
ElseIf myWord Like "[A-Z]*" And _
Not myWord Like "?*[!a-z]*" Then
Debug.Print "Text is proper case"
Else
Debug.Print "Text is mixed case"
End If
Rick
| |
| George Bashore 2005-12-14, 9:55 pm |
| Ralph
O'Brian would be propercase using replace function.
Take the ' out of the variable and add an empty space and put it back for
the msgbox printout.
I didn't think of all the possibilities for the different cases.
George
Option Explicit
Private Sub Command1_Click()
Dim myStr As String
myStr = Text1.Text
myStr = Replace(myStr, "'", " ")
Select Case myStr
Case UCase(myStr)
MsgBox myStr & " is " & "Uppercase"
Case LCase(myStr)
MsgBox myStr & " is " & "Lowercase"
Case StrConv(myStr, vbProperCase)
MsgBox Replace(myStr, " ", "'") & " is " & "Propercase"
Case Else
MsgBox myStr & " is " & "Is not UCase, LCase or ProperCase" & _
vbNewLine & "It must be Mixed Case."
End Select
End Sub
Private Sub Form_Load()
Command1.Caption = "Check Case"
End Sub
"Ralph" <nt_consulting64@yahoo.com> wrote in message
news:Y4idnU_v54jiVD3eRVn-uA@arkansas.net...
>
> "Bob Butler" <tiredofit@nospam.com> wrote in message
> news:uoLB1SOAGHA.3584@TK2MSFTNGP14.phx.gbl...
> eBay
> the
>
> Also, nobody has mentioned the ugly situation with "O'Brian". Which not
> only
> isn't *any* case - it tends to trash SQL. <g>
>
> -ralph
>
>
| |
|
|
"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
wrote in message news:OZKLrrRAGHA.2704@TK2MSFTNGP15.phx.gbl...
>
> Here is another method that has not been mentioned yet...
>
> Dim myWord As String
> myWord = Text1.Text
> If Not myWord Like "*[!A-Z]*" Then
> Debug.Print "Text is all upper case"
> ElseIf Not myWord Like "*[!a-z]*" Then
> Debug.Print "Text is all lower case"
> ElseIf myWord Like "[A-Z]*" And _
> Not myWord Like "?*[!a-z]*" Then
> Debug.Print "Text is proper case"
> Else
> Debug.Print "Text is mixed case"
> End If
>
> Rick
>
Now all we need is that kid with the one-liner.
All those tests should fit into one Switch() statement. <g>
-ralph
| |
| Rick Rothstein [MVP - Visual Basic] 2005-12-14, 9:55 pm |
| > > Here is another method that has not been mentioned yet...
>
> Now all we need is that kid with the one-liner.
>
> All those tests should fit into one Switch() statement. <g>
Debug.Print Switch(Not myWord Like "*[!A-Z]*", "Upper case", _
Not myWord Like "*[!a-z]*", "Lower case", _
myWord Like "[A-Z]*" And _
Not myWord Like "?*[!a-z]*", "Proper case", _
True, "Mixed case")
<g>
Rick
| |
| Stefan Berglund 2005-12-15, 3:55 am |
| On Wed, 14 Dec 2005 14:22:32 -0500, "George Bashore" <gbashore@bcpl.net> wrote:
in <erYI5OOAGHA.3984@TK2MSFTNGP14.phx.gbl>
>Bob
>The OP ask about a word. What word has 123 or !@# in it?
>I was playing around with these numbers and characters and the code will
>disreguard the numbers and characters with small letters in the textbox.
>Without letters they will show UCase but if you put in small letters they
>will show LCase.
I would think that proper nouns and trademark names are proper exceptions to
~all~ capitalization rules.
---
Stefan Berglund
| |
|
|
"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
wrote in message news:u%23ub3GSAGHA.208@tk2msftngp13.phx.gbl...
>
> Debug.Print Switch(Not myWord Like "*[!A-Z]*", "Upper case", _
> Not myWord Like "*[!a-z]*", "Lower case", _
> myWord Like "[A-Z]*" And _
> Not myWord Like "?*[!a-z]*", "Proper case", _
> True, "Mixed case")
>
> <g>
>
> Rick
>
Very good.
<Polite Applause>
-ralph
| |
| Rick Rothstein [MVP - Visual Basic] 2005-12-15, 7:55 am |
|
"Ralph" <nt_consulting64@yahoo.com> wrote in message
news:VpudnYnamuMZ_DzenZ2dnUVZ_sidnZ2d@ar
kansas.net...
>
> "Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
> wrote in message news:u%23ub3GSAGHA.208@tk2msftngp13.phx.gbl...
>
> Very good.
>
> <Polite Applause>
<An even more humble bow>
<g>
Rick
|
|
|
|