Editing Basic code

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Philip Stott
Posts: 5
Joined: Wed Dec 19, 2018 5:30 pm

Editing Basic code

Post by Philip Stott »

I would be grateful for help on how to edit code. If I try to delete anything by any method other than backspacing the program crashes. And even backspace does not work to remove a blank line - it crashes. I can't remove text with CTRL X, it crashes. I can only copy with CTRL C and then backspace to get rid of the original. Can someone please tell me how to do simple editing of code. Thanks in advance Phliip
OpenOffice 4.1.6 on Windows 10
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: editing Basic code

Post by RoryOF »

Where are you editing the BASIC code? In OO Writer, or in the BASIC IDE?
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: Editing Basic code

Post by JeJe »

This shouldn't be happening. Perhaps its a Windows 10 or installation problem.

If you google OpenOffice 4.1.6 on Windows 10 crash and look through the first few results it might help you solve this.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Philip Stott
Posts: 5
Joined: Wed Dec 19, 2018 5:30 pm

Re: Editing Basic code

Post by Philip Stott »

Thanks Rory and Jele for responding.
I am working in the BASIC IDE in a spreadsheet. At least I think that is where I get to when I follow: Tools/Macros/Organize Macros/OpenOffice Basic
I am using Windows 10, which has been installed for at least 2 years and nothing like this has happened before.
I tried re-installing, did not work so I re-downloaded and re-installed and the result is exactly the same.
OpenOffice 4.1.6 on Windows 10
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: Editing Basic code

Post by JeJe »

Tools/Macros/Organize Macros/OpenOffice Basic... then what?

A dialog pops up... you find the name of your document in the "macro from" list... click on it... the "Standard" library appears... you click on that... then click the "new button" on the right hand side... a dialog pops up asking you to name the module... you name it click "okay" and you're in the IDE with this showing:

Code: Select all


REM  *****  BASIC  *****

Sub Main

End Sub
Your code needs to go in a sub procedure such as inbetween Sub Main and End Sub. Press f5 to run your code.

If you post what you're putting in the module we can look at it and maybe see why it crashes...
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Editing Basic code

Post by RoryOF »

This may be a manifestation of the recent Windows 10 update that caused OpenOffice instability. It is reported that a subsequent Win10 update cured the OO instability problem; I suggest telling Win10 to fully update, before trying anything else.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Philip Stott
Posts: 5
Joined: Wed Dec 19, 2018 5:30 pm

Re: Editing Basic code

Post by Philip Stott »

Thanks for the help.

It is definitely Windows 10. I loaded OO on a Windows 7 machine and it works perfectly
OpenOffice 4.1.6 on Windows 10
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Editing Basic code

Post by RoryOF »

I recently bought a bargain second-hand computer, which came with Win 10 on it. I decided to tell Win 10 to update - after 18 hours of connection to my internet, it hadn't finished (and internet connection was fully occupied, so I could do nothing else on another computer that needed internet). After the 18 hours I decided I didn't need Win10 and installed Xubuntu 18.04 on it.

The moral of the story - the Win10 update may take a loo-oo-ong time - perhaps leave it overnight to update.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Editing Basic code

Post by John_Ha »

RoryOF wrote:The moral of the story - the Win10 update may take a loo-oo-ong time - perhaps leave it overnight to update.
Leaving it overnight quite possibly will not fix it. You need to repair it yourself. I have a laptop which unfortunately runs W10 so I rarely use it and it had the problem.

What seems to happen is that W10 gets very back-level because it has not been updated for a while (as your presumably did while it was sitting in the shop, and my laptop did as I don't use it often). Doing an automatic update then fails, presumably because the update process now needs a recent update which has not yet been installed. You are in a classic "Catch 22" situation - you cannot do an update because you need an update to be able to do an update.

The staggering incompetence of Microsoft in being unable to update its own software never fails to amaze me.

The solution is to repair the Windows 10 update process. See repair windows 10 update which returns 721 million hits, giving you an idea of the scale of the problem. That is incompetence on an astonishing scale.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Editing Basic code

Post by John_Ha »

Philip Stott wrote:At least I think that is where I get to when I follow: Tools/Macros/Organize Macros/OpenOffice Basic
No.

Tools > Macros > Organise Macros > OpenOffice Basic ..., takes you to this screen:
Clipboard01.gif
where Module1 is the file C:\Users\xxxxxx\AppData\Roaming\OpenOffice\4\user\basic\Standard\Module1.xba
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Philip Stott
Posts: 5
Joined: Wed Dec 19, 2018 5:30 pm

Re: Editing Basic code

Post by Philip Stott »

I Left Windows 10 to update overnight and it did not fix the problem - I will have to try the update by hand route.

But I have come across a problem on the Windows 7 computer. Maths functions like SQRT, and LN bring the BASIC program to a stop with a message that this is an unknown function.

These functions work in the spreadsheet itself. How do I make BASIC recognize them ?
OpenOffice 4.1.6 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Editing Basic code

Post by Zizi64 »

But I have come across a problem on the Windows 7 computer. Maths functions like SQRT, and LN bring the BASIC program to a stop with a message that this is an unknown function.

These functions work in the spreadsheet itself. How do I make BASIC recognize them ?
The SQRT(), and LN() are cell functions. You can call them from StarBasic, but it is not a trivial task.
And there is similar functions in the Starbasic with different names: SQR(Number) and LOG(Number; Base)

Sample code for the two different function callings:

Code: Select all

REM  *****  BASIC  *****

Option Explicit


Function MySquareRootStarBasic(TheNumber as double)
'There is not any error handling in this sample function - for example: for the negative inputs 

	MySquareRootStarBasic = Sqr(TheNumber)
end function


Function MySquareRootCalcCellfunction(TheNumber as double)
'There is not any error handling in this sample function - for example: for the negative inputs 
 Dim oFunctionAccess as object
 Dim TheArray(0)
  
	oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
	TheArray(0) = TheNumber
	MySquareRootCalcCellfunction = oFunctionAccess.CallFunction( "SQRT", TheArray())

end function


Function MyLogNatStarBasic(TheNumber as double)
'There is not any error handling in this sample function - for example: for the negative inputs 

	MyLogNatStarBasic = Log(TheNumber, Exp(1))
end function


Function MyLogNatCalcCellfunction(TheNumber as double)
'There is not any error handling in this sample function - for example: for the negative inputs 
 Dim oFunctionAccess as object
 Dim TheArray(0)
  
	oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
	TheArray(0) = TheNumber
	MyLogNatCalcCellfunction = oFunctionAccess.CallFunction( "LN", TheArray())

end function
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Philip Stott
Posts: 5
Joined: Wed Dec 19, 2018 5:30 pm

Re: Editing Basic code

Post by Philip Stott »

Thanks.

I must say this a surprise - such a long-winded procedure for something so simple in the spreadsheet itself. I will try your solution.

Thanks again
OpenOffice 4.1.6 on Windows 10
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Editing Basic code

Post by RoryOF »

A recent posting (~24/36 hrs ago) on the OO developer list reports that a very recent Windows 10 update has cured OpenOffice crashing problems
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Editing Basic code

Post by Zizi64 »

I must say this a surprise - such a long-winded procedure for something so simple in the spreadsheet itself.
You can control all of the applications by calling the API functions (API: Application Programming Interface of the AOO/LO. It is basicly different thing than the VBA of the MS Office.) See Andrew Pitonyak's free macro programming books.


I will try your solution.
It is not "my solution". It is only a simple sample of the usage the API functions and the StarBasic.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: Editing Basic code

Post by JeJe »

I must say this a surprise - such a long-winded procedure for something so simple in the spreadsheet itself. I will try your solution.
A Basic wrapper for calling Calc's functions using Function Access would be a project for somebody if anyone wants one... googled and no-one seems to have done this already...
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply