|
-
Sep 23rd, 2005, 08:33 AM
#1
Thread Starter
Hyperactive Member
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.
-
Sep 23rd, 2005, 08:41 AM
#2
Fanatic Member
Re: Replacing Letters
VB Code:
For intCount = 1 to Len(listbox1.text)
If Mid(listbox1,intCount,1) = "i" Then
Mid(listbox1,intCount,1) = "L"
intCount = intCount + 1
End if
Next
-
Sep 23rd, 2005, 08:44 AM
#3
Thread Starter
Hyperactive Member
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
-
Sep 23rd, 2005, 08:45 AM
#4
Re: Replacing Letters
The following may work for you:
VB Code:
Private Sub Command1_Click()
Dim i%
If List1.ListCount = 0 Then Exit Sub
For i = 0 To List1.ListCount - 1
List2.AddItem StrConv(Replace(LCase(List1.List(i)), "i", "L"), vbProperCase)
Next i
End Sub
-
Sep 23rd, 2005, 08:48 AM
#5
Fanatic Member
Re: Replacing Letters
VB Code:
Dim strListValue As String
strListValue = listbox1.text
For intCount = 1 to Len(strListValue)
If UCASE(Mid(strListValue) = "i") Then
Mid(strListValue,intCount,1) = "L"
intCount = intCount + 1
End if
Next
Listbox2.Text = strListValue
Try something like that.
-
Sep 23rd, 2005, 08:50 AM
#6
Re: Replacing Letters
VB Code:
Option Explicit
Private Sub ChangeLetter(pstrOldLetter As String, pstrNewLetter As String)
Dim i As Long
For i = 0 To List1.ListCount - 1
List2.AddItem List1.List(i)
List2.List(i) = Replace(List2.List(i), pstrOldLetter, pstrNewLetter)
Next
List1.Clear
End Sub
Private Sub Command1_Click()
ChangeLetter "i", "l"
End Sub
Private Sub Form_Load()
List1.AddItem "Ricky"
List1.AddItem "Richard"
End Sub
-
Sep 23rd, 2005, 08:58 AM
#7
Thread Starter
Hyperactive Member
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 ??
-
Sep 23rd, 2005, 09:00 AM
#8
Re: Replacing Letters
 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?
-
Sep 23rd, 2005, 09:01 AM
#9
Thread Starter
Hyperactive Member
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.
-
Sep 23rd, 2005, 09:06 AM
#10
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.
-
Sep 23rd, 2005, 09:08 AM
#11
Fanatic Member
Re: Replacing Letters
VB Code:
Dim strListValue As String
Dim blnAddValue As Boolean
blnAddValue = False
strListValue = listbox1.text
For intCount = 1 to Len(strListValue)
If UCASE(Mid(strListValue) = "I") Then
blnAddValue = True
Mid(strListValue,intCount,1) = "L"
intCount = intCount + 1
End if
Next
If blnAddValue = True Then
Listbox2.Text = strListValue
End if
-
Sep 23rd, 2005, 09:33 AM
#12
Thread Starter
Hyperactive Member
Re: Replacing Letters
VB Code:
Public Sub DoIt(OldLetter As String, NewLetter As String)
Dim I As Integer
Dim NewWord As String
For I = 0 To LstWord.ListCount - 1
[COLOR=Red]If InStr(LstWord.List(I), [/COLOR] OldLetter) Then
NewWord = LstWord.List(I)
NewWord = Replace(NewWord, OldLetter, NewLetter)
LstGened.AddItem NewWord
Next I
Else
Next I
End If
End Sub
would this work ?
And its complaining about the red line aswel any 1 explain ?
-
Sep 23rd, 2005, 11:48 AM
#13
Thread Starter
Hyperactive Member
Re: Replacing Letters
can anyone expand on my code above ? i think im close but not sure.
-
Sep 23rd, 2005, 12:36 PM
#14
Re: Replacing Letters
This works
VB Code:
Public Sub DoIt(OldLetter As String, NewLetter As String)
Dim i As Integer
Dim NewWord As String
For i = 0 To List1.ListCount - 1
If InStr(List1.List(i), OldLetter) Then
NewWord = List1.List(i)
NewWord = Replace(NewWord, OldLetter, NewLetter)
List2.AddItem NewWord
End If
Next
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|