Results 1 to 14 of 14

Thread: Replacing Letters Resolved

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Resolved Replacing Letters Resolved

    I need some code that will do the following.

    List1 contains

    Ricky
    Richard

    when i click command button it will add the following to list 2. Change a certain letter to a different letter. In this case i's to l's.

    RLcky
    RLchard

    And if possible have it so i can change the letters by having them as values when i call the function.

    Thanks in advance.
    Last edited by Ricky1; Sep 24th, 2005 at 06:33 AM.
    Im Learning !!!!

  2. #2
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Replacing Letters

    VB Code:
    1. For intCount = 1 to Len(listbox1.text)
    2.      If Mid(listbox1,intCount,1) = "i" Then
    3.         Mid(listbox1,intCount,1) = "L"
    4.         intCount = intCount + 1      
    5.     End if
    6. Next

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Replacing Letters

    that doesn't use the other list because i have got it to replace in the same list box but i want it to leave list1 as it is and add the new words to list2
    Im Learning !!!!

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

    Re: Replacing Letters

    The following may work for you:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim i%
    3.  
    4.     If List1.ListCount = 0 Then Exit Sub
    5.     For i = 0 To List1.ListCount - 1
    6.         List2.AddItem StrConv(Replace(LCase(List1.List(i)), "i", "L"), vbProperCase)
    7.     Next i
    8.  
    9. End Sub

  5. #5
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Replacing Letters

    VB Code:
    1. Dim strListValue As String
    2.  
    3. strListValue = listbox1.text
    4.  
    5. For intCount = 1 to Len(strListValue)
    6.      If UCASE(Mid(strListValue) = "i") Then    
    7.         Mid(strListValue,intCount,1) = "L"
    8.         intCount = intCount + 1      
    9.     End if
    10. Next
    11.  
    12. Listbox2.Text = strListValue

    Try something like that.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Replacing Letters

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub ChangeLetter(pstrOldLetter As String, pstrNewLetter As String)
    4. Dim i As Long
    5. For i = 0 To List1.ListCount - 1
    6.        List2.AddItem List1.List(i)
    7.        List2.List(i) = Replace(List2.List(i), pstrOldLetter, pstrNewLetter)
    8.    Next
    9.    List1.Clear
    10. End Sub
    11.  
    12. Private Sub Command1_Click()
    13. ChangeLetter "i", "l"
    14. End Sub
    15.  
    16. Private Sub Form_Load()
    17. List1.AddItem "Ricky"
    18. List1.AddItem "Richard"
    19. End Sub

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Replacing Letters

    thanks people, is there a way to do it so it wil only add words to list 2 that have had letters changed ??
    Im Learning !!!!

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Replacing Letters

    Quote Originally Posted by Ricky1
    thanks people, is there a way to do it so it wil only add words to list 2 that have had letters changed ??
    I don't understand what you mean?

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Replacing Letters

    well if list 1 had the folliwing

    Rick
    Ricky
    Space

    that i want to change i to l. So i would want

    Rlck
    Rlcky

    in list2 and them still left in list1. Didn't add space to list 2 because no letters got changed.
    Im Learning !!!!

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Replacing Letters

    Ok, yes you could do that, however, you would have to select, in the first listbox, which items you wanted to move, and then modify the code I originally posted to only look at selected items.

  11. #11
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Replacing Letters

    VB Code:
    1. Dim strListValue As String
    2. Dim blnAddValue As Boolean
    3.  
    4. blnAddValue = False
    5. strListValue = listbox1.text
    6.  
    7. For intCount = 1 to Len(strListValue)
    8.      If UCASE(Mid(strListValue) = "I") Then    
    9.         blnAddValue = True        
    10.         Mid(strListValue,intCount,1) = "L"
    11.         intCount = intCount + 1      
    12.     End if
    13. Next
    14.  
    15. If blnAddValue = True Then
    16.    Listbox2.Text = strListValue
    17. End if

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Replacing Letters

    VB Code:
    1. Public Sub DoIt(OldLetter As String, NewLetter As String)
    2.  
    3. Dim I As Integer
    4. Dim NewWord As String
    5.  
    6. For I = 0 To LstWord.ListCount - 1
    7.  
    8. [COLOR=Red]If InStr(LstWord.List(I), [/COLOR] OldLetter) Then
    9.     NewWord = LstWord.List(I)
    10.     NewWord = Replace(NewWord, OldLetter, NewLetter)
    11.     LstGened.AddItem NewWord
    12.     Next I
    13. Else
    14.     Next I
    15.  
    16. End If
    17.  
    18. End Sub

    would this work ?
    And its complaining about the red line aswel any 1 explain ?
    Im Learning !!!!

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Replacing Letters

    can anyone expand on my code above ? i think im close but not sure.
    Im Learning !!!!

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Replacing Letters

    This works
    VB Code:
    1. Public Sub DoIt(OldLetter As String, NewLetter As String)
    2.  
    3. Dim i As Integer
    4. Dim NewWord As String
    5.  
    6. For i = 0 To List1.ListCount - 1
    7.     If InStr(List1.List(i), OldLetter) Then
    8.         NewWord = List1.List(i)
    9.         NewWord = Replace(NewWord, OldLetter, NewLetter)
    10.         List2.AddItem NewWord
    11.     End If
    12. Next
    13. End Sub
    Note: You will need to change the listbox names back to what you have. I just put a couple on a test for to use while working this out.

    And, it does not remove the old words from the original list. You will need to add that as well (if that is the way you want to go.)

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