Page 1 of 1

Strange behaviour in For Next

Posted: Sat Jun 16, 2007 8:24 am
by Willy
This is a part of code that works already for years in an old Harbour FWH application

Code: Select all

Function RadFrm
Parameters aVelden,cDbf

Local Open1 , Open2, i:=0 , j :=0
Privat aTabs:={}, anReg:={5},Ptr:=0,lFolders := .F.,nPos := 100,;
       nButNr := 45

Dstk_Push()

Open2 := Is_Open_Dbf("Objekten",1)
Select Velden

* Bepaal of er folders voorkomen
For i := 1 To Len(aVelden)
   Goto aVelden[i]
   If !Empty(Velden->Folder)
      lFolders := .T.
      Ptr := aScan(aTabs,Velden->Folder)
      If Ptr = 0 && Niks gevonden
         Aadd(aTabs,Velden->Folder)
         Aadd(anReg,5)
      EndIf
      Ptr := Len(anReg)
   EndIf
Next


...
Now in the new HB and FWH it gives an error after executing the next line.

The error = Error Base 1086 Argument Error ++

In a small function that only consists of a for next, it works fine.

After rewriting the code with a do while structure incrementing i with the ++ operator the problem was still there.

Changing i++ in
i := i +1 gives a working solution.

But changing every for next in a do while is not the solution I think.

Any ideas ?

Greetings,

Willy Hermans

Posted: Sat Jun 16, 2007 9:02 am
by Antonio Linares
Willy,

Are you using xHarbour ? If yes, then please download it again from www.fivetechsoft.com/files/xharbour.exe as there was an error that got fixed by late May

Posted: Sat Jun 16, 2007 9:06 am
by Willy
No Antonio,
It was Harbour not xHarbour
Greetings,

Willy Hermans

Posted: Sat Jun 16, 2007 9:12 am
by Antonio Linares
Is it a very large PRG ? Whats its size ?

Posted: Sat Jun 16, 2007 9:55 am
by Willy
The whole PRG is about 15 KB

The whole function = 2902 bytes long

Greetings

Willy Hermans

Posted: Sat Jun 16, 2007 10:12 am
by Antonio Linares
Its quite strange and unusual. Are you sure that the error comes from the "next" line ?

Posted: Sat Jun 16, 2007 2:17 pm
by Willy
Antonio,

I see no other explanation.

I made another for next loop in a separated module in the same application. There it works fine.

Before the next statement I placed

Code: Select all

? i , Valtype(i)
The return was correct. Then after the first execution of next statement the error occurs.

So I changed the code to Do While ... EndDo
When I use the i:= i+1 the code works.

When I change it to i++
the same error occurs.

So in fact it is in the i++.

As far as I know the next statement is also translated tot <LoopVariabele>++

In other modules I have not found such an error. I shall see in the coming days how it evoluate.

In this module I have changed the code in Do While ... and i:=i+1

... and this works fine.

Thanks for the time you spended to this

Willy Hermans

Posted: Sat Jun 16, 2007 2:56 pm
by Enrico Maria Giordano
Can you build a reduced and complete sample showing the problem?

EMG

Posted: Sat Jun 16, 2007 3:03 pm
by Willy
Enrico,

I try to build an example and I shal post it.

However it is not possible for today anymore.

Thanks

Willy