I have a database with around 10,000 rows and the material is mostly quotes. So I don’t want to edit them, but I’d like to pull a random entry. The field of interest contains HTML text, and I’ve already figured out that I can set two Text Displays on a form and set one of them to be Rich Text and it must use NS rendering to convert it (it misses HTML entities like "e;
but gets all the format tags right – same behavior I’ve seen in applescript. I can see this being very handy for a report – think random quote of interest on a letter, invoice, etc.
So, perhaps clumsily, I’ve managed to piece this code together that does fetch a random field - the Field is named Text
(I known that I should probably rename that):
local Entries, winner
let Entries = arraybuild(cr(),"",{Text})
let winner = randomarrayelement(Entries, cr())
I’ve also used it as a Text Display’s formula by putting it in an execute|||
block and added: functionvalue winner
I prefer to have it on a button I press, so if I don’t like the first random one, I can click and get a new one before committing it to the use in the eventual form/report/etc.
Two problems I can’t figure out:
- if it’s on a button, how to I put the value into the Text Display? I’ve named the Text Display
frmWinner
and tried all sorts of hacks but nothing successfully so far. - if I leave it in the Text Display, what sort of button code would force the Text Display to reload?
One the side, this made me come up with an alternate hack – how could I change the focus of the form to be the single random record from the button? So far, I’m not seeing a way to just go to a random record – I can pick a random, I just don’t get how to go to record X
and have the form focus on it.
I think I will runto more trouble when I try to pass this along to another procedure later, but maybe not – since storing it in a variable should make it easy to pass the quote along.