Results 1 to 7 of 7

Thread: [RESOLVED] Formatting...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Resolved [RESOLVED] Formatting...

    Hi,

    Is there any way to change the words into "Sentence Case" as it can be done MS Office. Please let me know.

    Regards,


    Seema_S
    Attached Images Attached Images  

  2. #2

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Formatting...

    VB Code:
    1. Private Sub Form_Load()
    2.     Debug.Print SentenceCase("this is a test. is it a test? yes it is! a test.")
    3. End Sub
    4.  
    5. Private Function SentenceCase(ByVal sText As String)
    6.     Dim b() As Byte, N As Long, bChange As Boolean
    7.     b = sText
    8.     bChange = True
    9.     For N = 0 To UBound(b) Step 2
    10.         Select Case b(N)
    11.             Case 33, 46, 58, 63  ' !.:?
    12.                 bChange = True
    13.             Case 97 To 122 ' a-z
    14.                 If bChange Then b(N) = b(N) - 32: bChange = False
    15.             Case 32
    16.             Case Else
    17.                 bChange = False
    18.         End Select
    19.     Next N
    20.     SentenceCase = b
    21. End Function

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: Formatting...

    Quote Originally Posted by bushmobile
    VB Code:
    1. Private Sub Form_Load()
    2.     Debug.Print SentenceCase("this is a test. is it a test? yes it is! a test.")
    3. End Sub
    4.  
    5. Private Function SentenceCase(ByVal sText As String)
    6.     Dim b() As Byte, N As Long, bChange As Boolean
    7.     b = sText
    8.     bChange = True
    9.     For N = 0 To UBound(b) Step 2
    10.         Select Case b(N)
    11.             Case 33, 46, 58, 63  ' !.:?
    12.                 bChange = True
    13.             Case 97 To 122 ' a-z
    14.                 If bChange Then b(N) = b(N) - 32: bChange = False
    15.             Case 32
    16.             Case Else
    17.                 bChange = False
    18.         End Select
    19.     Next N
    20.     SentenceCase = b
    21. End Function
    Hi,

    Thanks. It is pretty nice. Now what I need is: when I enter a sentence in a textbox I will click on cmdSave button. So that the sentence entered should be saved in a Sentence Case format. Where should I call this function & what should be the line to call it?

    Call SentenceCase ....> when I am using this line in cmdSave button's code, getting an error "argument not optional"

    I have pasted the function code on the form. And calling it in cmdSave code.

    Regards,

    Seema_S

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Formatting...

    well, first off, I've missed something in my code - this function should be like this:
    VB Code:
    1. Private Function SentenceCase(ByVal sText As String) [B]As String[/B]
    well how you use the function is up to you. It accepts the text you want to change and outputs the changed version.e.g.:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Text1.Text = SentenceCase(Text1.Text)
    3. End Sub

  6. #6
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Formatting...

    Another way of doing that:

    How to make Sentence Case
    CS

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: Formatting...

    Quote Originally Posted by bushmobile
    well, first off, I've missed something in my code - this function should be like this:
    VB Code:
    1. Private Function SentenceCase(ByVal sText As String) [B]As String[/B]
    well how you use the function is up to you. It accepts the text you want to change and outputs the changed version.e.g.:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Text1.Text = SentenceCase(Text1.Text)
    3. End Sub
    Thanks a lot for the help.

    Regards,

    Seema_S

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width