| View previous topic :: View next topic |
| Author |
Message |
nasosan General User

Joined: 24 Jan 2008 Posts: 23 Location: carcare, savona, italia
|
Posted: Sun Aug 08, 2010 3:54 am Post subject: problem whit calc |
|
|
hi,
i have this code..
| Code: |
for x = 10 to 40
cell=sheet.getcellbyposition(3,x)
q=cell.value
if q>0 then
cell=sheet.getcellbyposition(0,x)
n=cell.string
for y = 1 to 6
sheet=thiscomponent.sheets(3)
cell=sheet.getcellbyposition(0,y)
an=cell.string
if n=an then
cell=sheet.getcellbyposition(4,y)
aq=cell.value
cell.value=aq-q
end if
next y
end if
next x
|
this work fine whit x=10...
for other value of x (11.12.13....40) it dosent take the right value of q... and dosent processed the firs if and other....
why?
if i try to set x=11 manualli and replace x whit 11 it works... if i try whit 12 it works.... but not iif a try to set x= (for cicle...) _________________ http://www.nasosan.it |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Sun Aug 08, 2010 5:59 am Post subject: |
|
|
You state that for certain values of X, you do NOT have the correct value of q. What if you include something like this untested code:
| Code: |
Print "Address row=" & cell.getCellAddress().Row & " col = cell.getCellAddress().Column
|
Do you retrieve the cell that you expect?
I suspect that either you have a bug in your code (ie, you have a logic error), or, there is a problem in how this macro is called.
For example, what is sheet? Is this the first sheet, the third sheet?
Is the macro called from a Calc function? If so, you cannot change cells on the sheet used to call the function. _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
nasosan General User

Joined: 24 Jan 2008 Posts: 23 Location: carcare, savona, italia
|
Posted: Sun Aug 08, 2010 7:26 am Post subject: |
|
|
| pitonyak wrote: |
Do you retrieve the cell that you expect?
I suspect that either you have a bug in your code (ie, you have a logic error), or, there is a problem in how this macro is called.
For example, what is sheet? Is this the first sheet, the third sheet?
Is the macro called from a Calc function? If so, you cannot change cells on the sheet used to call the function. |
i have used the control of macro.. the value of x is 10 the first time.. the second one is 11... the last is 40..
i have also tryed to print the value of x into a cell of my sheet... and the result are correct...
the sheet are correct.. the first time all works.. and if a put a volue in x the code work fine.. _________________ http://www.nasosan.it |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Sun Aug 08, 2010 9:37 am Post subject: |
|
|
Let's say you are working with Sheet1 & Sheet4. You define "sheet" as Sheet1 before the posted code. Then within the posted code you redefine "sheet" as Sheet4 so when X goes to 11 or above the code is always looking within Sheet4.
In other words, your first definition of "sheet" should be in the second line of the posted code. |
|
| Back to top |
|
 |
nasosan General User

Joined: 24 Jan 2008 Posts: 23 Location: carcare, savona, italia
|
Posted: Mon Aug 09, 2010 4:37 am Post subject: |
|
|
| JohnV wrote: | Let's say you are working with Sheet1 & Sheet4. You define "sheet" as Sheet1 before the posted code. Then within the posted code you redefine "sheet" as Sheet4 so when X goes to 11 or above the code is always looking within Sheet4.
In other words, your first definition of "sheet" should be in the second line of the posted code. |
i have found the error.. i have defined one time before the for x the sheet (0).... now i have put sheet (0) into for.. and work fine...
thanks _________________ http://www.nasosan.it |
|
| Back to top |
|
 |
|