Page 1 of 1

10 X 10 multiplication table in rev

Posted: Tue Sep 08, 2009 6:58 am
by urbaud
I want to create a 10 X 10 multiplication table for my grand daughter using Revolution. I can script it to have the numbers 1 - 10 displayed in a fld vertically with this code:
on mouseUp
repeat with x = 1 to 10
put x into line x of fld "t1"
end repeat
end mouseUp
and I can get the numbers to be displayed horizontilly with this code:
on mouseUp
repeat with x = 1 to 10
put x into char x of fld "t1"
end repeat
end mouseUp
but I don't know how to put the multiplication part (x * y) into the code. I don't know rev well enough to do it. Any help would be appreciated.

Posted: Tue Sep 08, 2009 11:06 am
by Mark Smith
Urbaud, something like this should do it:

Code: Select all

put 10 into tNum
repeat with n = 1 to 12
       put n && "times" && tNum && "is" && n * tNum & cr after tTable
end repeat
put tTable into fld 1

Best,

Mark

Posted: Tue Sep 08, 2009 2:27 pm
by urbaud
Mark,
Thanks so much for the quick reply to my problem. I'm sorry I didn't make myself clear when I described the 10 x 10 table. It's a matrix table and would be displayed something like this:
1 2 3 4.....10
2 4 6 8.....20
3 6 9 12...30
4 8 12 16...40
.
.
.
10
So, then she can multiply down and across using the rows and columns, or in rev terms, lines and chars. For example if she multiplies row 1, column 2 with column 1 row 2 the correct answer is 4 which is in row 2, column 2; likewise, 9 is the product of row 1, column 3 times column 1, row 3. Thank you again for your response. I don't know if something like this can be done in rev. I am able to do it in Visual Basic, which I know much better than rev. I want to try to do it in rev so I can learn rev.

Posted: Tue Sep 08, 2009 2:41 pm
by SparkOut
Try nesting your repeat loops:

Code: Select all

   --make a field "multiplicationTable" and set tabstops to a suitable value, say 30

   put empty into field "multiplicationTable" 
   --if you need to initialise it to empty, as the use of the keyword "after" below
   --will leave the exisiting contents intact and append the new data to the end 

   repeat with i = 1 to 10

      repeat with j = 1 to 10
         put i * j & tab after field "multiplicationTable"
         --that will build up each line as tab separated values
      end repeat

      put cr after field "multiplicationTable"
      --after each line has been built up, move down to next line
   end repeat

Posted: Tue Sep 08, 2009 3:05 pm
by urbaud
SparkOut,

Thanks so much. It's exactly what I wanted. And thanks for the quick response. A question, using the word 'after' in the lines of code: put i * j & tab after field "multiplicationTable" and put cr after field "multiplicationTable" seems odd to me. I can see using the word after in the following circumstances: put 'after' text in fld 1 or put 'after' word 2 in line 4 of fld 1, etc. but not after a field. This is a new use of the word for me. I'll have to look it up to learn more about it. Any comments you might have about the use of the word would be greatly appreciated.

Posted: Tue Sep 08, 2009 4:32 pm
by SparkOut
Just as you can

Code: Select all

put <somedata> "into" <somecontainer>
you can use "before" and "after" in place of "into" at will.
"into" will set the contents of the container (whether it be a variable/field/whatever) to be the data you specified, replacing any contents the container may have.
"before" will add the data you specified in front of the existing data in the container.
"after" will add the data you specified appended to the end of the existing data in the container.
Comparing it with "into" and thinking of "containers" rather than "fields", it is simple to see how the syntax works, I hope.

Posted: Tue Sep 08, 2009 4:37 pm
by SparkOut
Oh, just a side issue here - this is a very short and simple routine to build the table, so there is not a problem.
Be aware though, that updating field contents is very resource intensive for the engine compared to other processing and so updating the field directly like this is not good practice, generally speaking.
If you put the multiplied values "after" theMultiplicationTable variable in the repeat loop and then put theMultiplicationTable into field "multiplicationTable" at the end, it will be a much better habit to get into.