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

Using thisComponent

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
wpeter2002
OOo Enthusiast
OOo Enthusiast


Joined: 08 Apr 2007
Posts: 145

PostPosted: Mon Jun 25, 2007 5:45 am    Post subject: Using thisComponent Reply with quote

I am putting together a simple Calc application which guides the user through a selection process using a multi-page dialog. I have encountered problems when I have taken subs, which work, and tied several of them to a single button. My first mistake was my failure to make the dialog a global variable (Thank you to Bernard Marcelly for putting me straight on that one). However, I’m still getting “object variable not set” errors which I think may be due to my miss-use of “thisComponent”.

I have been using it to identify the document I am using so in this simple Calc application it refers to the Calc document. I suspect its use is more complex than the way I’m using it. I would be most obliged if you would explain how “thisComponent” should be employed.

For example, the code below works great when run from a button but when run from the IDE I get the error message:
“object variable not set” and the code
Code:
If isNumeric(oText.Text) then

is highlighted .
Best regards

Peter
Code:
Sub btnManuEntry_click
   Dim oText as Object
   Dim oCell as Object
   oCell = thisComponent.Sheets.getByName("SheetA").getCellByPosition (10,2)
   oText = oDialog1.GetControl ("ComboBoxA")
   If isNumeric(oText.Text) then
   oCell.Value = oText.Text
   Else
   oCell.String = oText.Text
   End If
   page2
End Sub
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Mon Jun 25, 2007 6:14 am    Post subject: Reply with quote

If the code is saved with a document, thisComponent always refers to this document having the code. If the code is saved in a global container like "My Macros" then it refers to the currently active document, not counting the IDE. When you call it from the IDE, you may get a wrong document (the wrong spreadsheet, a previously active text or even a help-document).
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
wpeter2002
OOo Enthusiast
OOo Enthusiast


Joined: 08 Apr 2007
Posts: 145

PostPosted: Mon Jun 25, 2007 9:43 am    Post subject: Reply with quote

Villeroy,
Thank you for your explanation.

Best regards

Peter
Back to top
View user's profile Send private message
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