Re: Array issue

2009-04-02 Thread Terry Judd
Hi Mike - this doesn't necessarily answer the question of why, but if you
put empty into iHisto before the inner repeat loop instead of after it then
the result of the two methods is the same. Note that without 'emptying' it
first you often don't get the expected number of reps within iHisto (more
sometimes, less other times). Not sure whether this is down to random or
arrays.

Terry...


On 3/04/09 11:08 AM, "Michael Lew"  wrote:

> Dear listers
> 
> I have struck an unexpected issue with an array. I assumed that the two
> following code snipets would be equivalent, but they are not.
> 
> Version 1 
> put random(10)-1 into tnum
> add 1 to iHisto[tnum]
> Version 2
> add 1 to iHisto[(random(10)-1)]
> 
> Version 1 does what I expected, and, I guess is more readable and so
> preferable for that reason. However, I can't see why the two versions differ
> in their effects.
> 
> Here is the full code of my button for anyone who wishes to try it out (the
> different versions are indicated with comments):
> 
> on mouseUp pMouseBtnNo
> put 1 into oreps
> put 100 into ireps
> set the cursor to busy
> repeat oreps
> put 0 into kount
> repeat ireps
> add 1 to kount
> -- **next two lines
> -- put random(10)-1 into tnum
> -- add 1 to iHisto[tnum]
> -- **OR the next one line
> add 1 to iHisto[(random(10)-1)]
> --
> end repeat --inner
> combine iHisto by return and comma
> sort lines of iHisto numeric descending by item 2 of each
> add 1 to ohisto[item 2 of line 1 of iHisto]
> put empty into iHisto
> end repeat --outer
> combine oHisto with return and tab
> sort lines of oHisto numeric ascending by word 1 of each
> put oHisto into fld "OutputFld"
> end mouseUp
> 
> Thanks,
> Michael Lew
> 
> ___
> use-revolution mailing list
> use-revolution@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Array issue

2009-04-02 Thread Michael Lew
Dear listers

I have struck an unexpected issue with an array. I assumed that the two
following code snipets would be equivalent, but they are not.

Version 1 
put random(10)-1 into tnum
add 1 to iHisto[tnum]
Version 2
add 1 to iHisto[(random(10)-1)]

Version 1 does what I expected, and, I guess is more readable and so
preferable for that reason. However, I can't see why the two versions differ
in their effects.

Here is the full code of my button for anyone who wishes to try it out (the
different versions are indicated with comments):

on mouseUp pMouseBtnNo
put 1 into oreps
put 100 into ireps
set the cursor to busy
repeat oreps
put 0 into kount
repeat ireps
add 1 to kount
-- **next two lines
-- put random(10)-1 into tnum
-- add 1 to iHisto[tnum]
-- **OR the next one line
add 1 to iHisto[(random(10)-1)]
--
end repeat --inner
combine iHisto by return and comma
sort lines of iHisto numeric descending by item 2 of each
add 1 to ohisto[item 2 of line 1 of iHisto]
put empty into iHisto
end repeat --outer
combine oHisto with return and tab
sort lines of oHisto numeric ascending by word 1 of each
put oHisto into fld "OutputFld"
end mouseUp

Thanks,
Michael Lew

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution