Page 1 of 1

Repeat into label Field

Posted: Fri Jun 10, 2016 10:52 am
by pjfry
Hi there

this is my code snippet

Code: Select all

on mouseUp
   local diceRolls, diceEyes, diceResult
   if field fldDice is an integer and field fldDice < 11 and field fldDice > 0 and field fldEye is an integer then
      put field fldDice into diceRolls
      put field fldEye into diceEyes
      repeat diceRolls times
         put random(diceEyes) & ", " after diceResult
         put diceResult[X] into field lblDiceResult X
      end repeat
      put diceResult & CR before field fldProtocol
      
      end if
end mouseUp
My Programm should rolle dice and put the results into a scroll field an into Label fields.

The scollfield called fldProtocol works just fine, but I habe a Problem with the labelfields.

So lets say I have 3 rolls with a 6-side dice so i like to put result 1 into field lblDiceResult1 result 2 into lblDiceResult2 and result 3 into lblDiceResult3

put I have no idea how to achieve this.

Maybe yout have an idea?

Thanks Benny

Re: Repeat into label Field

Posted: Fri Jun 10, 2016 2:36 pm
by Klaus
Hi Benny,

ouch! 8)

OK, try this one and please read the comments:

Code: Select all

on mouseUp
   local diceRolls, diceEyes, diceResult
   
   ## 1. ALWAYS put quotes around object names!
   ## 2. Accessing fields is MUCH slower than accessing variables, 
   ## so do  not access a field more than once, put them into variables instead!
   put fld "fldDice" into diceRolls
   put field "fldEye" into diceEyes
   if diceRolls is an integer and diceRolls < 11 and diceRolls > 0 and diceEyes is an integer then
      
      ## To be able to concatenate object names, we need this approach "repeat with ..."!
      repeat with i = 1 to diceRolls
         
         ## First generate the random number:
         put random(diceEyes) into tRandomEyes
         
         ## Now put value into appropriate field:
         put tRandomEyes into fld ("lblDiceResult" & i)
         
         ## Collect all values:
         put tRandomEyes & ", " after diceResult
      end repeat
      put diceResult & CR before field "fldProtocol"
   end if
end mouseUp
Best

Klaus

Re: Repeat into label Field

Posted: Fri Jun 10, 2016 9:52 pm
by pjfry
Hi Klaus,

first thank you very much for your great help. Your Code works fine :)

I will try so respect your tipps in future :) Thanks for this

Benny