Problem returning values from a function written in vbscript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dsmith76
    New Member
    • Dec 2011
    • 5

    Problem returning values from a function written in vbscript

    When I use this code, it works fine:

    <% Function RandomNumber(in tHighestNumber)
    Randomize
    RandomNumber = Int(Rnd * intHighestNumbe r) + 1
    End Function
    SEEDNMBR=(Rando mNumber(16))
    Response.Write SEEDNMBR %>
    However, with the code below I get this error code:Microsoft VBScript compilation error '800a03ea'
    Syntax error
    /seed_modify_bat ch.asp, line 20
    Function RandomNumber(in tHighestNumber)
    ^
    This is the code that results in the above error:
    <% for i=1 to 16
    Function RandomNumber(in tHighestNumber)
    Randomize
    RandomNumber = Int(Rnd * intHighestNumbe r) + 1
    End Function
    SEEDNMBR=(Rando mNumber(16))
    Response.Write SEEDNMBR
    next
    %>
    FYI, I am using the function to generate 16 random integers from 1 to 16 so I can "seed" a golf bracket in a blind draw, or random fashion. Also, if I enclose the code in <script type="text/vbscript"> the function does not work even if the first example above. I am running this code on an active server page. I never need to use the script tags on any pages that I have on my website.
    Thanks for help. Dave
    Last edited by dsmith76; Dec 23 '11, 12:46 AM. Reason: typos
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    There's no need to redefine the function. And you definitely can't define it in a loop.

    Comment

    Working...