| View previous topic :: View next topic |
| Author |
Message |
wpeter2002 OOo Enthusiast

Joined: 08 Apr 2007 Posts: 145
|
Posted: Mon Jun 25, 2007 5:45 am Post subject: Using thisComponent |
|
|
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 |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Mon Jun 25, 2007 6:14 am Post subject: |
|
|
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 http://forum.openoffice.org |
|
| Back to top |
|
 |
wpeter2002 OOo Enthusiast

Joined: 08 Apr 2007 Posts: 145
|
Posted: Mon Jun 25, 2007 9:43 am Post subject: |
|
|
Villeroy,
Thank you for your explanation.
Best regards
Peter |
|
| Back to top |
|
 |
|