Results 1 to 19 of 19

Thread: Case Help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Case Help

    Ok im trying to make a progam where i can load a list of words and click a buttom called sort.

    I know the code for lower case and upper case.

    Whats the code for Sentance Case ???? Rick, Scoot, Paul examples.



    Also i want to separate lines that begin with numbers ? How would i do this.
    Example

    69ers
    999Police
    Rick
    Paul

    so 69ers and 999Police would go in list2 and Rick and Paul will go in list 1.
    Probably quite simple but i need help.
    Im Learning !!!!

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Case Help

    Something like this might work for you:
    VB Code:
    1. Select Case Sentence
    2.     Case "Rick"
    3.         'do something
    4.     Case "Scoot"
    5.         'do something
    6.     Case "Paul"
    7.         'do something
    8. End Select
    9.  
    10. 'also use Left() to check if first character is numeric
    11. If IsNumeric(Left(some_string_variable, 1)) Then
    12.     'string begins with number
    13. Else
    14.     'regular string
    15. End If

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Case Help

    cool got the number thing working, ok but i wana do something like this for the sentance case, i want to take all the entries from list1 and make them sentance case and then add them to list 3.
    Im Learning !!!!

  4. #4
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Case Help

    Quote Originally Posted by Ricky1
    cool got the number thing working, ok but i wana do something like this for the sentance case, i want to take all the entries from list1 and make them sentance case and then add them to list 3.

    Define Sentance Case? If that just starting with a capital letter?

    If it is then try this:

    VB Code:
    1. Private Function IsSentanceCase(strString As String) As Boolean
    2.     Dim intKeyCode As integer
    3.     intKeyCode = Asc(Left(strString, 1)) ' Get the keycode of the first string character.
    4.     If intKeyCode >= 65 And intKeyCode <= 90 Then
    5.         IsSentanceCase = True
    6.     Else
    7.         IsSentanceCase = False
    8.     End If
    9. End Function


    Cheers,

    RyanJ
    Last edited by sciguyryan; May 11th, 2005 at 11:51 AM.
    My Blog.

    Ryan Jones.

  5. #5

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Case Help

    I wana take all the words in list1 and add them to list3 in sentence case, is what i want to do.
    Im Learning !!!!

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Case Help

    Try something like this for separating words starting with numbers from those that don't.

    VB Code:
    1. Const TEST_DATA = "69ers 999Police Rick Paul"
    2. Dim strParts() As String
    3. Dim lngIndex As Long
    4.  
    5. strParts = Split(TEST_DATA, " ")
    6.  
    7. For lngIndex = 0 To UBound(strParts)
    8.     If IsNumeric(Left$(strParts(lngIndex), 1)) Then
    9.         lstNumbers.AddItem strParts(lngIndex)
    10.     Else
    11.         lstLetters.AddItem strParts(lngIndex)
    12.     End If
    13. Next

  8. #8
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Case Help

    Quote Originally Posted by Ricky1
    I wana take all the words in list1 and add them to list3 in sentence case, is what i want to do.

    In that case, try something like this:

    VB Code:
    1. Dim I As Integer
    2. List3.Clear ' Clear the listbox
    3. For I = 0 To List1.ListCount
    4.     List3.AddItem List1.List(I)
    5. Next I


    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Case Help

    but thats just gona add them to list 3 as they are in list1. Not wot i want it to do.
    Im Learning !!!!

  10. #10
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Case Help

    Quote Originally Posted by Ricky1
    but thats just gona add them to list 3 as they are in list1. Not wot i want it to do.

    I was presuming you were going to reorder the List1 first. (Reorder as in do yuor sorting things.)



    RyanJ
    My Blog.

    Ryan Jones.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Case Help

    no i need something like this.

    Code:
    Dim i as Integer
    Dim str As String
    For i = 0 to list1.listcount - 1
    
    str = list1.list(i)
    ' code to make it sentance case
    list3.additem str
    
    next i
    
    end sub
    I just can't do the hard bit.
    Im Learning !!!!

  12. #12

  13. #13
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Case Help

    Quote Originally Posted by MartinLiss
    I'm still unsure what you mean by "sentence case".

    Same here, I have never heared of that one before either.


    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Case Help

    Sentance Case = 1st Letter Cap

    lowercase = rick
    uppercase = RICK
    sentence case = Rick
    Im Learning !!!!

  15. #15
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Case Help

    Then what I posted should work:

    VB Code:
    1. Private Function IsSentanceCase(strString As String) As Boolean
    2.     Dim intKeyCode As integer
    3.     intKeyCode = Asc(Left(strString, 1)) ' Get the keycode of the first string character.
    4.     If intKeyCode >= 65 And intKeyCode <= 90 Then
    5.         IsSentanceCase = True
    6.     Else
    7.         IsSentanceCase = False
    8.     End If
    9. End Function

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Case Help

    yeah that tells me if it is sentence case, but i wana make it sentance case if it isn't aswel. How i do that ??
    Im Learning !!!!

  17. #17
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Case Help

    Quick and dirty!

    VB Code:
    1. Dim i As Integer
    2. Dim str As String
    3. For i = 0 To list1.ListCount - 1
    4.   str = UCase(Left(list1.List(i), 1)) & _
    5.        Right(list1.List(i), Len(list1.List(i)) - 1)
    6.   list3.AddItem str
    7. Next i

  18. #18
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Case Help

    Quote Originally Posted by Ricky1
    yeah that tells me if it is sentence case, but i wana make it sentance case if it isn't aswel. How i do that ??

    Ah, right, try this:

    VB Code:
    1. Private Function UpperFirst(strString As String) As String
    2.     Dim intCharacter As Integer
    3.     Dim strSection As String
    4.     intCharacter = Asc(Left(strString, 1))
    5.     If intCharacter < 97 Or intCharacter > 122 then
    6.         UpperFirst = strString
    7.     Else
    8.         strSection = Right(strString, Len(strString) - 1)
    9.         UpperFirst = Chr(intCharacter - 32) & strSection
    10.     End if
    11. End Function


    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Case Help

    lol dg you always answer my questions.
    Cheers For The Help Every1 Im Getting Somewhere Now.
    Im Learning !!!!

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