How can I select the value of an active cell in calc

In VisualB it is ActiveCell.Value, but I cannot seem to find it in LOBasic.

This is my VB script:

command = ActiveCell.Value

If Left(command, 3) = "10." Then

command = "ping " + command

End If

If Left(command, 4) = "ping" Then

vbReturn = Shell(command, vbNormalFocus)

Else

vbReturn = MsgBox("Select Ping Command or IP Address" & vbCrLf & "Then Press: Execute Ping Command", vbOKOnly)

Exit Sub

End If

I’d greatly appreciate any help I can get. I’m assuming the vbReturn and vbOKOnly may also be different.

There may be a few words in VB having an exact equivalent in LibO Basic - and even fewer are identical. At least when access to objects (documents and everything inside them) and their properties comes in account, the two follow completely different concepts. The gap might be wider than that between Kisuaheli and Mandarin.

There won’t be a predefined object like ‘ActiveCell’. The one predefined object variable of that style I know is ‘ThisComponent’ and its “value” may as well be a Writer document as a Calc document or a document of any class LibreOffice is knowing of. Just ‘This’! If ‘ThisComponent’ actually is a Calc document (and will conatain Calc cells, among them, may be, something like an ‘ActiveCell’) you will have to test by a method call. ‘ThisComponent.supportsService(“com.sun.star.sheet.SpreadsheetDocument”)’ will return TRUE if so and FALSE otherwise. But you won’t actually need to do that. If your Sub was called from a Calc document you know in advance.

Any document class should possess a method ‘getCurrentSelection()’ and, talking of a Calc document it will return an object, let’s assign it as value to oSel, which then can answer the question ‘oSel.supportsService(“com.sun.star.sheet.SheetCell”)’. If the answer is TRUE you may use the property value ‘oSel.Value’ and proceed. You also may prepare an error-handling and try ‘oSel.Value’ without a preceding test.

If you actually want to program in LibO Basic or to “convert” VB code to it, you should start studying “The Book” and the “Useful Information” by Andrew Pitonyak, both available here in odt and in pdf as well. I only go to Basic if unavoidable. The very few things I know about it I got from the sources mentioned above.

Editing

As soon as there is a valid object of the cell class, say oCell [ you may check by:

If oCell.supportsService("com.sun.star.sheet.SheetCell") ], you have access to any of its properties, among them ‘Value’, ‘String’ and ‘Formula’. There are also the related methods ‘getValue()’, ‘setValue(NewValue)’ and the respective ones.

Confer listing 6.6 in A. Pitonyak’s “Useful … Informations”, p 139, version 2014-06-14.

I know javascript and python is supported too as macros, what else can be used?

The support - in principle - for any programming language/system someone wrote an uno-implementation and bridge for is, imo, the reason for accepting some complications coming with the uno concept. The extensive incompatibility with VBA on the othert hand, is due to the uno-concept, too - and to the portability requirements.

However, I am not the one to answer your questions from profound knowledge. Hope someone else will do. You may have a look into http://www.openoffice.org/udk/.

I took a look at Pitonyak’s macro guide, and while I was able to figure out getting the address of the active cell, I still can’t figure out getting the value of the cell and saving it to a variable, so I can then run a command with it.