Creating gets with a For... next

Creating gets with a For... next

Postby Rafael Clemente » Fri Mar 30, 2007 11:30 am

I am trying to create about 30 gets with a For... next loop. Something like this:
Code: Select all  Expand view
// --- Initialize
oGet := {}
aGet := {}
For i := 1 TO 30
     AADD(oGet, Nil)
     AADD(aGet, Str(i))
Next
// --- Create Gets:
nR := 0; nC := 0
For i := 1 TO 30
     nR, nC GET oGet[i] Var aGet[i]
     nR += 1
Next

But this example doesn't work: All the gets show the last value (30) . Anybody could suggest a way of solving this problem?. Thanks
Rafael
User avatar
Rafael Clemente
 
Posts: 365
Joined: Sat Oct 08, 2005 7:59 pm
Location: Barcelona, Spain

Re: Creating gets with a For... next

Postby Maurilio Viana » Fri Mar 30, 2007 12:08 pm

Rafael, try any like this:

Code: Select all  Expand view
(...)
For i := 1 TO 30
     nR, nC GET oGet Var cGet
     oGet[i] := oGet
     cGet[i] := cGet
     nR += 1
Next


I think the problem will be most clear if you compile with /p and seek the .ppo generated file... This is a codeblock problem were the program at runtime see only last item (i = 30).
Maybe if you call for the class directly and use macro (&) to compose the code block (&("{|| .....}")) it will do what you want...

xxx := TGet():New(.....)

Sorry if I'm not very clear...
I did any like this times ago using menus. I'm not in my house now, but when I go back I'll search in my computer. (But I think Antonio will let you a solution very near).

Regards!
Maurilio
User avatar
Maurilio Viana
 
Posts: 252
Joined: Tue Oct 25, 2005 2:48 pm
Location: Garça/Garza/Heron City - Brazil

Postby Rafael Clemente » Fri Mar 30, 2007 12:21 pm

Maurilio:

Thanks for your suggestion, but it doesn't seem to work. After the for...next loop, ? oGet[i]:VarGet() gives the same value (the last one) for all the gets

I'll take a look at the codeblock and see if I find a workaround

Best regards,

Rafael
User avatar
Rafael Clemente
 
Posts: 365
Joined: Sat Oct 08, 2005 7:59 pm
Location: Barcelona, Spain

Postby Enrico Maria Giordano » Fri Mar 30, 2007 3:01 pm

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL aGet[ 2 ]

    LOCAL aVar := { SPACE( 20 ), SPACE( 20 ) }

    LOCAL i

    DEFINE DIALOG oDlg

    FOR i = 1 TO 2
        MAKEGET( aGet, aVar, i )
    NEXT

    ACTIVATE DIALOG oDlg;
             CENTER

    ? aVar[ 1 ], aVar[ 2 ]

    RETURN NIL


STATIC FUNCTION MAKEGET( aGet, aVar, n )

    @ n, 1 GET aGet[ n ] VAR aVar[ n ]

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Rafael Clemente » Sat Mar 31, 2007 7:33 am

Enrico:
Worked beautifully! Once more, thanks!
Rafael
User avatar
Rafael Clemente
 
Posts: 365
Joined: Sat Oct 08, 2005 7:59 pm
Location: Barcelona, Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 65 guests