Jump to content

Random position of something.


m33tmn

Recommended Posts

Hi all, i was hoping someone here could help me, i'm very unexperienced with ASP but i need to change something in a .aspx file. i want an object to be displayed at a random position. generating random numbers got me completely stuck. i currently have:

<DIV STYLE="position:absolute; LEFT: 145px; TOP: 25pt">

i would like to change 145 and 25 to 2 random (different) numbers between 5 and 600. could anyone help me with that? if you know asp it can't be hard :) thanks, marc

Link to comment
Share on other sites

HiHere you have a function that receives two parameters (highest and lowest number), the "Do Untill" loop provides you a random number between those two parameters, then you just have to put those values into your top and left variables.

<%Function RandomNumber(intLowestNumber,intHighestNumber)      Do Until (RandomNumber >= intLowestNumber) And (RandomNumber <= intHighestNumber)      Randomize      RandomNumber = Int(Rnd * intHighestNumber) + 1	LoopEnd FunctionleftRndNumber = RandomNumber(5,600)topRndNumber = RandomNumber(5,600)%>

Happy programming :)

Link to comment
Share on other sites

and it still gives me errors.....

<%Function RandomNumber(intLowestNumber,intHighestNumber)     Do Until (RandomNumber >= intLowestNumber) And (RandomNumber <= intHighestNumber)     Randomize     RandomNumber = Int(Rnd * intHighestNumber) + 1LoopEnd Function%><DIV STYLE="position:absolute; LEFT: <% =RandomNumber(5,600) %>px; TOP: <% =RandomNumber(5,600) %>pt">Hello</div>

doesn't work.... server error in '/' application.... blahblah i'm sure you know it :)thanks, marc

Link to comment
Share on other sites

Server Error in '/' Application.--------------------------------------------------------------------------------Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30289: Statement cannot appear within a method body. End of method assumed.Source Error: Line 3:    <DIV align="center"><STRONG><FONT face="Verdana" color="#ffffff" size="4">National Prison</FONT></STRONG>Line 4:  <%Line 5:  Function RandomNumber(intLowestNumber,intHighestNumber)Line 6:      Do Until (RandomNumber >= intLowestNumber) And (RandomNumber <= intHighestNumber)Line 7:      Randomize Source File: c:\inetpub\wwwroot\X.aspx    Line: 5
detailed information also available, if needed...thanks, marc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...