Get in a loop

Post Reply
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Get in a loop

Post 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!?
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Get in a loop

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
IBTC
Posts: 103
Joined: Sat Oct 18, 2008 8:13 pm
Location: Stuttgart, Germany
Contact:

Re: Get in a loop

Post 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 ] )
Best Regards,
Ruediger Alich

---
HMG 3.1.3 | FTDN/FWH 13.12 | Harbour 3.2 | BCC/MinGW | Windows XP/Vista/7/8/10 (32/64-Bit), Wine (Linux/Mac) - started 1999 with FW, 1989 with Clipper
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: Get in a loop

Post 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!
Regards,
Günther
---------------------------------
office@byte-one.com
Post Reply