Basic function to return cell contents

Spreadsheet has many sheets. Want to write a basic function that will return the numerical value stored in a particular cell (that is in the same location) in all the sheets. Something like

Function AddFromSheet(Optional nSheet)

If IsMissing(nSheet) Then

AddFromSheet = ThisComponent.getCurrentController().getActiveSheet().$C$4

Else

AddFromSheet = ThisComponent.getSheets().getByIndex(nSheet-1).$C$4

EndIf

End Function

Obviously this doesn’t work, but, in general, how does one specify (in the basic programming language) the contents of a particular cell? In the example above, cell C4 contains a real number. I want the function to return this number.

Just figured it out. Cell.getValue is the magic bullet:

Function AddFromSheet(Optional nSheet)

If IsMissing(nSheet) Then

Cell=ThisComponent.getCurrentController().getActiveSheet().getCellRangeByName("C4")

AddFromSheet = Cell.getValue

Else

Cell=ThisComponent.getSheets().getByIndex(nSheet-1).getCellRangeByName("C4")

AddFromSheet = Cell.getValue

EndIf
End Function