Creating gets with a For... next

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

Creating gets with a For... next

Post by Rafael Clemente »

I am trying to create about 30 gets with a For... next loop. Something like this:

Code: Select all

// --- 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
Maurilio Viana
Posts: 252
Joined: Tue Oct 25, 2005 2:48 pm
Location: Garça/Garza/Heron City - Brazil
Contact:

Re: Creating gets with a For... next

Post by Maurilio Viana »

Rafael, try any like this:

Code: Select all

(...)
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
Rafael Clemente
Posts: 365
Joined: Sat Oct 08, 2005 7:59 pm
Location: Barcelona, Spain

Post by Rafael Clemente »

Maurilio:

Thanks for your suggestion, but it doesn't seem to work. After the for...next loop, ? oGet: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
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Code: Select all

#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
Rafael Clemente
Posts: 365
Joined: Sat Oct 08, 2005 7:59 pm
Location: Barcelona, Spain

Post by Rafael Clemente »

Enrico:
Worked beautifully! Once more, thanks!
Rafael
Post Reply