Results 1 to 12 of 12

Thread: [RESOLVED] Coverting words to other words

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    Resolved [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

  2. #2
    Addicted Member Piller's Avatar
    Join Date
    Oct 2004
    Location
    california
    Posts
    177

    Re: Coverting words to other words

    You would have to use the replace function

    VB Code:
    1. Private Sub Command1_Click()
    2. Text1.Text = Replace(Text1.Text, Text1.SelText, Text2.Text)
    3. End Sub

    That replaces the selected text is text1 with what evers is text2.

    VB Code:
    1. Private Sub Command1_Click()
    2. Text1.Text = Replace(Text1.Text, "Then", Text2.Text, , , 1)
    3. 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.
    Are we alive or just breathing?

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    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?

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    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"

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

    Re: Coverting words to other words

    here's a way in which it could be done:

    VB Code:
    1. Private Function RandomReplace(ByVal sSource As String, ByVal sWord As String) As String
    2.   Dim sRandom As String
    3.   Randomize
    4.  
    5.   Do Until Not CBool(InStrB(sSource, sWord))
    6.     Select Case sWord
    7.       Case "Then"
    8.         sRandom = Choose(Int(3 * Rnd + 1), "Next", "After", "Later")
    9.         sSource = Replace(sSource, sWord, sRandom, , 1, vbBinaryCompare)
    10.     End Select
    11.   Loop
    12.   RandomReplace = sSource
    13. End Function
    14.  
    15. Private Sub Command1_Click()
    16.   Text1.Text = RandomReplace(Text1.Text, "Then")
    17. End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    Re: Coverting words to other words

    Thanks soo much thats perfect

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

    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    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??

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

    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?

  10. #10

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    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?

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

    Re: Coverting words to other words

    Well you can add extra cases for other words:

    VB Code:
    1. Private Function RandomReplace(ByVal sSource As String, ByVal sWord As String) As String
    2.   Dim sRandom As String
    3.   Randomize
    4.  
    5.   Do Until Not CBool(InStrB(sSource, sWord))
    6.     Select Case sWord
    7.       Case "Then"
    8.         sRandom = Choose(Int(3 * Rnd + 1), "Next", "After", "Later")
    9.       Case "and"
    10.         sRandom = Choose(Int(2 * Rnd + 1), "also", "plus")
    11.     End Select
    12.     sSource = Replace(sSource, sWord, sRandom, , 1, vbBinaryCompare)  
    13.   Loop
    14.   RandomReplace = sSource
    15. End Function

    or you may want to adopt a different approach and loop through every word and consider each case separately.

  12. #12

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    Re: Coverting words to other words

    Thats pretty much it for me thanks everyone... and congrads Bushmobile on your 400th post

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