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

Newbie needs help with for loop :)

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


Joined: 02 Dec 2005
Posts: 29

PostPosted: Mon Dec 12, 2005 8:13 am    Post subject: Newbie needs help with for loop :) Reply with quote

Code:
Sub Macro1
       Dim oSheetDsc as object
   Dim i as integer
   Dim aRow as object
   For o = 0 To 50
   i = 7
   'set your sheet name
     oSheetDSC = ThisComponent.Sheets.getByName("Sheet1")

     aRow = oSheetDsc.rows(i)
   aRow.isStartOfNewPage = true
   i  = i + 7
   o = 0 + 1
   Next o
End Sub


So, I want to make a page break after the next 7 rows, 50 times.
What's wrong with my loop?

Regards Johan, rookie
Back to top
View user's profile Send private message Visit poster's website
Laurent Godard
General User
General User


Joined: 16 Mar 2003
Posts: 47
Location: Grenoble (France)

PostPosted: Mon Dec 12, 2005 8:29 am    Post subject: Reply with quote

Hi
only dealing with the loop, i would say
Code:
   For j = 1 To 50
       i = j*7
       'set your sheet name
       oSheetDSC = ThisComponent.Sheets.getByName("Sheet1")
       aRow = oSheetDsc.rows(i)
       aRow.isStartOfNewPage = true
   Next j


The for loop automatically increases the variable used for the loop
avoid to use o or l as varaible names

Laurent
Back to top
View user's profile Send private message Visit poster's website
JohnV
Administrator
Administrator


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

PostPosted: Mon Dec 12, 2005 11:25 am    Post subject: Reply with quote

And this would be an wrong if nothing else, "o = 0 + 1". Presumably you meant, "o = o +1", which supports the advice, "avoid to use o or l as varaible names".
Back to top
View user's profile Send private message
grkn
General User
General User


Joined: 02 Dec 2005
Posts: 29

PostPosted: Mon Dec 12, 2005 11:57 am    Post subject: Reply with quote

Thanks, worked like it should!
Back to top
View user's profile Send private message Visit poster's website
Laurent Godard
General User
General User


Joined: 16 Mar 2003
Posts: 47
Location: Grenoble (France)

PostPosted: Mon Dec 12, 2005 1:00 pm    Post subject: Reply with quote

ok

one last point
you should move
Code:
oSheetDSC = ThisComponent.Sheets.getByName("Sheet1")

outside of the loop

Laurent
Back to top
View user's profile Send private message Visit poster's website
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