Page 1 of 1

Random Variable in a column

Posted: Sun Dec 15, 2013 1:21 pm
by jakea782
I'm trying to find a way to assign a random column to display in a text field after I assign mouseUp to a button. So right now this is my code to display the random variable for the row but I only know how to assign one column.

put the dgDataOfLine[random(22)] of grp "WordsChart" of stack "FWsub" into FirWord
put FirWord["Nouns"] into FirWordValue
put FirWordValue into field "FirstWord" <--- that is the text field that displays the word

So on mouseUp, I click the button and it puts a random number into FirWord. It then assigns the column "Nouns" into FirWordValue. The word that is assigned to this cell that is the random number and in column "Nouns" is then displayed. What can I do to assign a random column instead? All my columns are named and I have eight of them.

Re: Random Variable in a column

Posted: Sun Dec 15, 2013 1:41 pm
by Klaus
Grüezi Jakea782,

you can use the "dgProp["columns"] for this:
...
put the dgDataOfLine[random(22)] of grp "WordsChart" of stack "FWsub" into FirWord

## Get a random line of this CR delimited list:
put any line of the dgProp["columns"] of grp "WordsChart" of stack "FWsub" into tRandomKey

## Or to visualize the single staps:
## 1. Get list of columns:
## put the dgProp["columns"] of grp "WordsChart" of stack "FWsub" into tColumnList
## 2. get a RANDOM line from this list:
## put ANY line of tColumnList into tRandomKey

put FirWord[tRandomKey] into field "FirstWord"
...

I recommend to load the DataGrid Docs in PDF format and read it at least 100 times!
Or more, if neccessary, that's what I did, and still have to when using datagrids anew
after a couple of days, they are so damn complex beasts! :D

Get it here: http://lessons.runrev.com/m/datagrid


Best

Klaus

Re: Random Variable in a column

Posted: Fri Dec 27, 2013 3:29 am
by jakea782
I never came back and thanked you for this. Merci Klaus!