Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Here is a fun little object I'm trying to implement into my template .qvw but I need a little help figuring something out. I have a simple spreadsheet that I am loading as a data island that contains small, simple tips for users. It's only two columns: a Tip_ID (integer starting at 1) and Tip_Text (usually no more than about 200 characters). Right now I have about 20 records but this will grow over time.
I want to display a text box on the opening sheet that displays a random tip from this loaded data. The tip displayed will change, randomly, every time the app opens. I'm also thinking of adding a button that the user can click on to display a new random tip (generate a new random number), just in case the the user wants to view other tips. But this latter feature is not required. The function for randomly choosing which tip to display needs to work between 1 and the max of the rows loaded from this spreadsheet. This app is ajax only, so a macro isn't a option. Any ideas?
You can generate a random number between 1 and x (where x is the number of records in your tip table) by doing the following:
floor(rand()*X+1)
To improve upon this, you could create a variable named say vNum. Create a button with an action to set the value of vNum equal to rand(), then use this equation:
floor(vNum*X+1)
Then put this into a textbox:
concat({<tip_id = {$(=floor(vNum*X+1)}>} tiptext)
Maybe an on open trigger selecting a value
Ceil(Rand()*Max({1} Tip_ID))
and then just displaying a text box with the actual tip text should do.
hope this helps
regards
Marco
Actually, this seems to have worked: =Ceil(rand()*Max(Tip_ID))
Unless there is mathimatical flaw with that method that I don’t see.
- Brian
Thanks for the input guys. This seems to be working:
vRandomTip: =Ceil(rand()*Max(Tip_ID))
List Box Expression: =If(Tip_ID=$(vRandomTip),[Tip Text])
Nice Marco! I'll have to try that in the ajax client though since I've had issues with the OnOpen trigger not working.