Results 1 to 5 of 5
  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} Fields (Word97)

    I'm puzzled that there is no RND()/RAND() function in the list obtainable through the Help files for Field Codes ("Field codes: = (Formula) field" then "For information about Functions").

    There are close-but-no-cigar fields such as {EditTime} and {FileSize}, but they don't suit when I want a series of pseudo-random values, one for each cell of a Word97 table.

    I know that there's the infamous "Quick brown Fox" random typing, as announced in Woody's newsletter WOW 8.12 (http://www.woodyswatch.com/office/ar...ate.asp?v8-n12) also 15 May 2003 Vol 8 No 17.

    I can't see a way to generate a random number in a equation field {= }.

    I've tried
    {=rand}
    {=rnd}
    {=rand()}
    {=rnd()}
    {=rand(7)}
    {=rnd(7)}
    without success.

    I'd make use of the Range.Start value, if I could work out how to get it into a {}. Thinking something like {EditTime} to give me a good-enough seed, a {Range.Start} to make each cell individual, and perhaps a {FileSize} thrown in for good measure. Between them all they would be random enough to throw a different cell into focus each time I used the table.

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

    Re: {Random} Fields (Word97)

    Some time ago, <!profile=Andrew Lockton>Andrew Lockton<!/profile> provided you with a way to generate random numbers. I dug the post up out of an archive:
    <hr>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>

    <hr>
    Hope you can (re-)use this.

  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} Fields (Word97)

    Hans, (Andrew!)

    Thanks for the refresh. I miss the Search SO MUCH!

    How'd you like a job as chief research officer (in charge of searching AGAIN) with me.

    The pay isn't much, but the home-made chutney is to cry over!

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

    Re: {Random} Fields (Word97)

    I dunno, if the chutney gets the same treatment as the soup...

  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} Fields (Word97)

    Good One!

    My very first batch ever - and it really DOES taste superb.

Posting Permissions

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