[RESOLVED] Coverting words to other words
I am seeking help for a program I am trying to make. First Off, my goal is to make a converter that will convert words you type in to another word... As in
If I typed In "and" and wished to convert it to "plus" or "also".... How would I go about doing this. My second question is.. If the first part was completed.. how would I make the converter use 2 to 3 options of a word to convert to....... example... If I had a paragraph with about 12 "then" words in it.. I would possibly want to use a variety of words like that.. so I would enter the paragraph into the converter and it would convert all of the "then" words to a conversion of random words Like "after" or "later"
Another example:
Before: Then he went to the park. Then he drove his car. Then he went home.
After. Then he went to the park. After he drove his car. Later he went home.
Is there any way of doing this?? The first question being answered is fine.. the second is just something that could be added. Thanks
Re: Coverting words to other words
You would have to use the replace function
VB Code:
Private Sub Command1_Click()
Text1.Text = Replace(Text1.Text, Text1.SelText, Text2.Text)
End Sub
That replaces the selected text is text1 with what evers is text2.
VB Code:
Private Sub Command1_Click()
Text1.Text = Replace(Text1.Text, "Then", Text2.Text, , , 1)
End Sub
This replaces all the "Then"'s in text1. The 1 at the end of the code makes it so capitals and lower case letters are all the same.
Re: Coverting words to other words
thanks, could you give me an example code of converting an actuall word?
Instead of the command,... could you add a word conversion so I can base it off that?
Re: Coverting words to other words
Alright maybe I didnt state what I wanted to do clearly... Basically I want to take a sentence.. and copy it into the converter.. lets say this sentance is -The car isn't blue, and isn't brown-. I would then put that into the converter and it would convert "isn't" into "is not"..... throughout the sentance..
If i took an essay and had too many uses of the word "and" in it.. I want to paste that into the converter (assuming that the converter knows the "and" should be changed to "also") and when it converts all the "and"s in the paragraph would then turn into "also"s instead of "and"
Re: Coverting words to other words
here's a way in which it could be done:
VB Code:
Private Function RandomReplace(ByVal sSource As String, ByVal sWord As String) As String
Dim sRandom As String
Randomize
Do Until Not CBool(InStrB(sSource, sWord))
Select Case sWord
Case "Then"
sRandom = Choose(Int(3 * Rnd + 1), "Next", "After", "Later")
sSource = Replace(sSource, sWord, sRandom, , 1, vbBinaryCompare)
End Select
Loop
RandomReplace = sSource
End Function
Private Sub Command1_Click()
Text1.Text = RandomReplace(Text1.Text, "Then")
End Sub
Re: Coverting words to other words
Thanks soo much thats perfect :D
Re: Coverting words to other words
Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer. Also if someone has been particularly helpful, or even particularly unhelpful, you have the ability to affect a their forum "reputation" by rating their post.
Re: Coverting words to other words
Im sorry bust one last question before I resolve this thread...
Bushmobile.. I haev to highlight the text in the textbox.. Is there a way to just click the command button without highlighting the text??
Re: Coverting words to other words
that shouldn't need to have the text highlighted. Are you sure you haven't accidently put Text1.SelText instead of Text1.Text or something like that?
Re: Coverting words to other words
Ok your right.. must have screwed up the code earlier... but Bushmobile.. what If I were to add another word after "then".. how would I continue the code?
Re: Coverting words to other words
Well you can add extra cases for other words:
VB Code:
Private Function RandomReplace(ByVal sSource As String, ByVal sWord As String) As String
Dim sRandom As String
Randomize
Do Until Not CBool(InStrB(sSource, sWord))
Select Case sWord
Case "Then"
sRandom = Choose(Int(3 * Rnd + 1), "Next", "After", "Later")
Case "and"
sRandom = Choose(Int(2 * Rnd + 1), "also", "plus")
End Select
sSource = Replace(sSource, sWord, sRandom, , 1, vbBinaryCompare)
Loop
RandomReplace = sSource
End Function
or you may want to adopt a different approach and loop through every word and consider each case separately.
Re: Coverting words to other words
Thats pretty much it for me thanks everyone... and congrads Bushmobile on your 400th post :)