OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

problem whit calc

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
nasosan
General User
General User


Joined: 24 Jan 2008
Posts: 23
Location: carcare, savona, italia

PostPosted: Sun Aug 08, 2010 3:54 am    Post subject: problem whit calc Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Sun Aug 08, 2010 5:59 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address
nasosan
General User
General User


Joined: 24 Jan 2008
Posts: 23
Location: carcare, savona, italia

PostPosted: Sun Aug 08, 2010 7:26 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Sun Aug 08, 2010 9:37 am    Post subject: Reply with quote

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
View user's profile Send private message
nasosan
General User
General User


Joined: 24 Jan 2008
Posts: 23
Location: carcare, savona, italia

PostPosted: Mon Aug 09, 2010 4:37 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group