Get in a loop

Get in a loop

Postby byte-one » Thu Feb 17, 2011 2:11 pm

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  Expand view
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
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Get in a loop

Postby nageswaragunupudi » Thu Feb 17, 2011 2:34 pm

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  Expand view
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
nageswaragunupudi
 
Posts: 10259
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Get in a loop

Postby IBTC » Thu Feb 17, 2011 2:34 pm

Maybe file test128.prg in FWH samples folders helps you. Try something like this:

Code: Select all  Expand view
  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
IBTC
 
Posts: 103
Joined: Sat Oct 18, 2008 8:13 pm
Location: Stuttgart, Germany

Re: Get in a loop

Postby byte-one » Thu Feb 17, 2011 3:14 pm

Thanks!
And in which way i make the WHEN-Block?

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

Code: Select all  Expand view
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
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 11 guests