FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Get in a loop
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Get in a loop
Posted: Thu Feb 17, 2011 02: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 (fw): Select all Collapse
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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Get in a loop
Posted: Thu Feb 17, 2011 02: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 (fw): Select all Collapse
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
Posts: 103
Joined: Sat Oct 18, 2008 08:13 PM
Re: Get in a loop
Posted: Thu Feb 17, 2011 02:34 PM
Maybe file test128.prg in FWH samples folders helps you. Try something like this:

Code (fw): Select all Collapse
   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
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: Get in a loop
Posted: Thu Feb 17, 2011 03:14 PM
Thanks!
And in which way i make the WHEN-Block?

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

Code (fw): Select all Collapse
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

Continue the discussion