problem with get in a for loop

23 views
Skip to first unread message

miguel

unread,
Jun 4, 2012, 7:41:45 AM6/4/12
to Harbour Users
Hi,

I'm learning Harbour, so there maybe a simple answer to this.

When I run a get inside a for loop the get I get a strange behavior.
The say will always begin by displaying the second iteration index -
in this case i=2, but I've tried starting with a different i and the
result is always i+1
This also, results in getlist[i] == nil // where is is the first value
of the for loop index

function main()
local getlist
local tb := Array(5)
local i
local n
setmode(24,75)

clear screen
clear gets

for i=1 to len(tb)
@1,1 say str(i) + "Value: " get n
read
tb[i]:=n
n:=0
next

@10,10 say tb[1]
inkey(0)

return nil

Txs for the help,
miguel

Massimo Belgrano

unread,
Jun 4, 2012, 8:44:32 AM6/4/12
to harbou...@googlegroups.com
is very bad pratice have a read inside a  for 
and when you made you need remember
lifetime of getlist and add GetList := {}, 

2012/6/4 miguel <mig.e...@gmail.com>
--
Massimo Belgrano


miguel

unread,
Jun 4, 2012, 9:25:23 AM6/4/12
to Harbour Users
Ok.

If it's bad practice I'll refrain from doing it.

What do you mean about the lifetime of getlist?
I "suppose" being declared local will make it available inside the
main function. What am I missing?

Please note that I'm a beginner and have been reading about clipper
but I have not found much free resources. So I very much appreciate
any help I get or links to resources where I could learn more.

Txs,
miguel


On Jun 4, 1:44 pm, Massimo Belgrano <mbelgr...@deltain.it> wrote:
> is very bad pratice have a read inside a  for
> and when you made you need remember
> lifetime of getlist and add *GetList* := {},
>
> 2012/6/4 miguel <mig.e.lo...@gmail.com>
>

José M. C. Quintas

unread,
Jun 4, 2012, 12:08:52 PM6/4/12
to harbou...@googlegroups.com
You put n := 0 after get, and in first get it has no value.
 
Try:
Local n := 0 // default to N
 
Or, in the style of your source:
 
Afill( tb, 0 ) // Default value for each array element
for i=1 to len(tb)
   n := tb[i] // assign old value
   @1,1 say str(i) + "Value: " get n
   read
   tb[i]:=n
next
 
José M. C. Quintas
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

Evangelos Tsakalidis

unread,
Jun 4, 2012, 12:29:13 PM6/4/12
to harbou...@googlegroups.com
Hallo.

I think that your broblem is there : "   @1,1 say str(i) + "Value: " get n  ".
In one place you want to have many gets...

Tsakalidis G. Evangelos
Serres / Greece

2012/6/4 José M. C. Quintas <josed...@mandic.com.br>

miguel

unread,
Jun 4, 2012, 4:08:23 PM6/4/12
to Harbour Users
That's it. If n was initialized it wouldn't be a problem.
So I think that maybe the get systems prefers vars to be initialized
(even if untrue, it should not hurt).

Txs,
miguel

On Jun 4, 5:08 pm, José M. C. Quintas <josedon...@mandic.com.br>
wrote:
> You put n := 0 after get, and in first get it has no value.
>
> Try:
> Local n := 0 // default to N
>
> Or, in the style of your source:
>
> Afill( tb, 0 ) // Default value for each array element
...
Reply all
Reply to author
Forward
0 new messages