Page 1 of 1

Get in a loop

Posted: Thu Feb 17, 2011 2:11 pm
by byte-one
I have 60 fields with names I_1, I_2, I_3, and so on. Now i will produce gets for this fields in a loop.

Code: Select all

for i = 1 to 60
nii := ltrim(str(i))
Tget():redefine(1000+i, bSETGET(erf->I_&nii), oDlg,,"#",erf->I_&nii < 10)
next
But this is not functioning!?

Re: Get in a loop

Posted: Thu Feb 17, 2011 2:34 pm
by nageswaragunupudi
Codeblocks created like this in for next loops never work the way you may expect. All the codeblocks use the value of the variable after exiting from the loop, in this sample, 61.

In such cases, codeblocks should be constructed in separate functions, using the concept of detached locals.

This code works:

Code: Select all

for i = 1 to 60
   Tget():redefine(1000+i, bGetBlock( i ), oDlg,,"#" )
next

// ----
// ----

static function bGetBlock( i )
return FieldWBlock( "I_" + LTrim( Str( i ) ), Select( "erf" ) )

 
You need to construct bValid block also in the same manner through separate function and use.

Re: Get in a loop

Posted: Thu Feb 17, 2011 2:34 pm
by IBTC
Maybe file test128.prg in FWH samples folders helps you. Try something like this:

Code: Select all

   n = 1
   for nRow = 1 to 15
      for nCol = 1 to 10
          TGet():New( nRow - 0.5, nCol * 2 - 0.7, GenBlock( aValues, n++ ) )
      next
   next   

---

function GenBlock( aValues, n )
return bSETGET( aValues[ n ] )

Re: Get in a loop

Posted: Thu Feb 17, 2011 3:14 pm
by byte-one
Thanks!
And in which way i make the WHEN-Block?

I try to make the WHEN-Block in the loop:

Code: Select all

for i = 1 to 60
   tget():redefine(...........when_block(i,variable))
next

function when_block(i,n)
return {||i>n}
But when i change variable no effect!