Results 1 to 14 of 14
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    {random text} fields (Word97/SR2)

    Has anyone ever created a random-text generator field?

    This is something that I THOUGHT should be a cinch with Field Codes: A few nested braces, an equals sign, a call to RAND() and a set of strings, perhaps a COUNT, maybe fifteen minutes construction and Bingo!

    However, In Word97 I see no Rand() function for the = operator; I can get TIME, I suppose, and use it as the basis for a crude random number generator. There is a COUNT but it seems (to me) to work only on numbers and bookmarks rather than strings.


    Here's the goal: I want (a macro that will solicit a set of strings and then generate inline) a field that will generate just one of a set of strings at random. (I'm developing form letters, and Ii want each one to look sincere!)

    Eaxample: "You might be eligible for a refund" could be regenerated as "You may be eligible for a refund" or "You could be eligible for a refund" or even "You ought to be eligible for a refund".

    To this end I'd want a field that looked like this:

    { ONEOF ("might", "may", "could", ought to") }

    It's the ONEOF function that has me stumped. I can write the macro to generate the field.

    I would like the fucntion to be its own randomizer, so that selecting the entrire document and updating all fields would cause a different one of the four options above to be generated, and as well affect the outcome of { ONEOF ("Use", "Employ", "Email to us") } and also { ONEOF ("frozen", "closed", "locked") }

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: {random text} fields (Word97/SR2)

    I hope for you that others will contradict me, but I don't think that such a field exists in Word (up to and including Word 2002).

    I assume that you are aware of the =rand() and =rand(m,n) generators in Word - if you type =rand(3,5) in a document followed by Enter, you'll get 3 paragraphs of 5 sentences each. Not very random, though - all sentences are equal: The quick brown fox jumps over the lazy dog.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: {random text} fields (Word97/SR2)

    (See also the start of the macro work here).



    >hope for you that others will contradict me, but I don't think that such a field exists

    Hans, you fail me! (grin). It's something to think about as I drift off to sleep tonight, soemthing to occupy my mind while I wait for soemthing to happen ......



    >=rand() and =rand(m,n) generators in Word

    Yes, thank you. I think that that is why I felt there would be a RAND function in {Fields}. Odd, isn't it? There is a randomiser function, of sorts, present. I guess that I expect every appliaction to provide a basic set of functions such as Min, Max, Avg, Rand, Trim, left, Right and so on.

    Sigh.

    Anyway, I'm working on it ......

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: {random text} fields (Word97/SR2)

    I'm ready with the marketing slogan. "At last, an advanced letter generator which uses technology to fake sincerity"

    If other text on the form letter is coming from a mail merge - what about using the randomiser in excel to generate some of the 'personalisations'. At the very least it can pass a random number and an If field can do the rest in Word.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: {random text} fields (Word97/SR2)

    > text on the form letter is coming from a mail merge

    It is not. I have a plain old Word document.

    We just want to ring a few changes, introduce subtle variations so as not to bore the operators. As in

    "You can click the button" vs. 'You can choose the button", and so on.


    There are other applications, such as building an index. If I have identified synonyms and lodged them in situ as a comment, i can, later on, examine the comments and generate appropriate {XE} fields automatically.

    Give me five more mnutes and I'll dream up other uses.



    > "At last, an advanced letter generator which uses technology to fake sincerity"

    I could <font color=yellow>make</font color=yellow> a few <font color=yellow>changes</font color=yellow> in <font color=yellow>this</font color=yellow> to make it <font color=yellow>sound</font color=yellow> more <font color=yellow>human</font color=yellow> (grin!)

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: {random text} fields (Word97/SR2)

    Chris

    Perhaps you could fake a randomiser for use in your fake sincerity generator if you use the Time field set to seconds. For all intents and purposes {time @ "s"} gives me a random number between zero and sixty. I have a feeling I could work out the algorithm if I refreshed the field fast enough but it appears pretty random if I run it once every hour or so.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: {random text} fields (Word97/SR2)

    Getting there! Thanks Andrew.

    Here is a hand-built field for a triple-string; that is, assuming I have harvested three words that could be swapped in or out - "interpretations", "meanings" and "forms".

    <pre>{ if { time @ "s" } < 20 interpretations { if { time @ "s" } < 40 meanings forms } }
    </pre>

    It has this general form:
    <pre>{ if rnd < 20 alpha { if rnd < 40 beta gamma } }
    </pre>

    I have the macro to harvest the synonyms; I know my goal, I need now to develop the algorithm to generate the fields nested according to the number of strings.

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: {random text} fields (Word97/SR2)

    This Post has the vba code. Appears to work fine.

    Thanks again, Andrew, for the insight. Or as we say in the trade DumpIfs(15, 15, "Sincerely Truly Happily Joyously", " ").

    Honest!

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: {random text} fields (Word97/SR2)

    Andrew, I have done a bit more work on the fake randomiser. Honest!

    The problem with using a consistent "seconds" value in each list means that some combinations appear twinned, and others not at all.

    For example, a 20-second parsing of "alpha beta gamma" with a 15-second parsing of "one two three four" means that "one" always appears with "alpha" (leading 15 seconds of any minute) and "four" always appears with "gamma", but never with "alpha".

    I dug back years to Pseudo-random number generation, and remembered that multiplying by a prime is useful.

    This web site provided a list of the first 1,000 prime numbers, so I experimented with 3 different prime numbers immediately above 60 (seconds) and the results appear OK.

    The three sample fields below are for 3-word strings.

    <pre>{ = mod (( 67 * {time @ "s"} ),3 ) # "0" }
    { = mod (( 71 * {time @ "s"} ),3 ) # "0" }
    { = mod (( 73 * {time @ "s"} ),3 ) # "0" }
    </pre>


  10. #10
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: {random text} fields (Word97/SR2)

    Well if a fake randomiser isn't good enough, how about a real one. If you run code to create some genuine random numbers to be stored as document variables, then the field can pick that up with a field update.

    Populate your document with a few fields
    {DOCVARIABLE Random1}
    {DOCVARIABLE Random2} etc

    then run this code
    <pre>Function funRandomise(iNum As Integer) As Integer
    funRandomise = Rnd() * iNum
    End Function
    Sub SetRandomVars()
    Dim iCount As Integer, myVar As Variable

    For Each myVar In ActiveDocument.Variables
    If Left(myVar.Name, 6) = "Random" Then myVar.Delete
    Next myVar

    For iCount = 1 To 10
    ActiveDocument.Variables.Add Name:="Random" & iCount, Value:=funRandomise(100)
    Next iCount

    ActiveDocument.Fields.Update
    End Sub</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  11. #11
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: {random text} fields (Word97/SR2)

    > Well if a fake randomiser isn't good enough, how about a real one

    I didn't want to be that sincere (grin).

    Nice effort.

    No, GREAT effort.

    I'd like to take your code and hook it up to a dictionary of synonyms, establish randomization for words and phrases on an automatic basis. Stay tuned. All I need now is a dictionary of synonyms.

  12. #12
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: {random text} fields (Word97/SR2)

    <<All I need now is a dictionary of synonyms.>>

    Seems like the thesaurus in Word would be a good place to start - all you need to do is to figure out how to manipulate it's object module. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Meanwhile I'll figure out how to use the spell checker!
    Wendell

  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: {random text} fields (Word97/SR2)

    > thesaurus in Word ... figure out how to manipulate it's object module.

    <pre>Sub test()
    Dim mylang, mythes
    mylang = Selection.LanguageID
    Set mythes = Languages(mylang).ActiveThesaurusDictionary
    MsgBox mythes.Path & Application.PathSeparator & mythes.Name
    End Sub
    </pre>


    So far I've discovered that it has a DELETE method (oops!)


    > Meanwhile I'll figure out how to use the spell checker!

    If you're serious, let's talk. A year or so ago I embarked upon a better spell-checker, one that anticipated corrections by storing previous responses to 'Ignore All", and pre-determined substitutions as data modules within a document. I wanted more than a passive Custom Dictionary; I wanted the smarts to avoid the spell-checker asking me the same darn questions about the same dran words in each new document.


    My two hurdles are

    (1) Macro Virus protection rears its ugly head for a Module, even 'though it just contains commented data strings.

    (2) The incredible slowness of word-by-word spell-checking (as in For Each wrd in doc.Words). I may have a better solution - extracting the unique words of a range and checking just those, rather than checking each occurrence of the same word.

  14. #14
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: {random text} fields (Word97/SR2)

    Not serious - I have enough complications in my life already. I was actually noting that had mis-spelled thesaurus, and should have used the Lounge spell checker.
    Wendell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •