Page 1 of 1
Creating gets with a For... next
Posted: Fri Mar 30, 2007 11:30 am
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
Re: Creating gets with a For... next
Posted: Fri Mar 30, 2007 12:08 pm
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
Posted: Fri Mar 30, 2007 12:21 pm
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
Posted: Fri Mar 30, 2007 3:01 pm
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
Posted: Sat Mar 31, 2007 7:33 am
by Rafael Clemente
Enrico:
Worked beautifully! Once more, thanks!
Rafael