Visual Basic programmers, Help needed!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • More Booze
    Confirmed User
    • Mar 2004
    • 5116

    #1

    Visual Basic programmers, Help needed!

    I wrote a function which picks a random word from a listbox.
    The function is called "RANDOMWORD".

    I got a textbox with the text
    "Hi I am (WORD). I like to (WORD) and (WORD)."

    I want to replace all (WORD) with random words but if
    I use
    document = Replace(document, "(WORD)", RANDOMWORD)
    it will change all (WORD) to the same random word.

    How should I do to get a new word for each (WORD) in the textbox?
    (In the exeample its only 3 (WORD) but it vary)
  • malakajoe
    Confirmed User
    • Feb 2003
    • 1751

    #2
    I am far from a VB expert...but try this maybe.

    Build an array first and then insert from that array.

    Again, don't know much and probably won't work.
    Selfpleasure.com for sale on auction. Closes on Tuesday March 11th at 9pm PST!!!!

    Dirty enough to be good, but clean enough for everyone!
    ------------------------------------------------------------------

    Moral Police - First graduating class coming soon! - Forcing our values across the internet

    Comment

    • NickPapageorgio
      Confirmed User
      • Apr 2004
      • 8323

      #3
      I don't know VB but I would imagine it is much like anything else. Build an array of all the different (WORDS) you want and then build a function to randomize those words as needed.

      Comment

      • bobosoft
        Confirmed User
        • Mar 2003
        • 152

        #4
        Which version of VB is it?

        Comment

        • More Booze
          Confirmed User
          • Mar 2004
          • 5116

          #5
          Its Visual Basic 6.0.

          I dont know how the array thing could work better, I already can pick random words the problem is that I cant replace (WORD) without use the same random word for all.

          Or maby you meant that I could grab the textbox and make it into a array and then loop throu it and replace the words one by one..
          Hmm that may work.

          Comment

          • NickPapageorgio
            Confirmed User
            • Apr 2004
            • 8323

            #6
            I was saying maybe build an array and function for each (WORD) box. So 3 different sets of arrays and functions. But then again I don't know VB so someone with more experience would probably have a better suggestion.

            Comment

            • bobosoft
              Confirmed User
              • Mar 2003
              • 152

              #7
              for VB 6.0 thats an easy one.

              the replace function is laid out like this

              Replace(expression, find, replacewith[, start[, count[, compare]]])


              you have the first three required operators but you omitted the optional operators

              start is the place in the string to start looking for words to replace. the first character is default.

              count is the important one, it is the number of replacement to make. the defaul is -1 which meams make as many replacements as possible. simply change the value to 1 and it will only make 1 replacement at a time.

              your code would look something like this for 3 replacements

              Dim i as integer
              For i = 1 to 3

              RANDOMWORD = RanddomwordFunction()
              document = Replace(document, "(WORD)", RANDOMWORD,1,1)

              Next i
              or if you wanted to unlimited replacements you oudl have it loop until document is the same as it waqs when it started

              do

              Document2 = document
              RANDOMWORD = RanddomwordFunction()
              document = Replace(document, "(WORD)", RANDOMWORD,1,1)

              loop until document = document2

              Comment

              • More Booze
                Confirmed User
                • Mar 2004
                • 5116

                #8
                YES!!!! thanks alot bobosoft, it fucking WORKED!
                I asked about this in 4 programmer forums but nobody could answer.

                Comment

                • bobosoft
                  Confirmed User
                  • Mar 2003
                  • 152

                  #9
                  Originally posted by More Booze
                  YES!!!! thanks alot bobosoft, it fucking WORKED!
                  I asked about this in 4 programmer forums but nobody could answer.
                  Of course not, the brightest of the brightest all hang around gfy.

                  Comment

                  Working...