Page 1 of 1

Editing Basic code

Posted: Wed Dec 19, 2018 5:51 pm
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

Re: editing Basic code

Posted: Wed Dec 19, 2018 6:23 pm
by RoryOF
Where are you editing the BASIC code? In OO Writer, or in the BASIC IDE?

Re: Editing Basic code

Posted: Wed Dec 19, 2018 11:02 pm
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.

Re: Editing Basic code

Posted: Thu Dec 20, 2018 6:02 am
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.

Re: Editing Basic code

Posted: Thu Dec 20, 2018 10:34 am
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...

Re: Editing Basic code

Posted: Thu Dec 20, 2018 10:50 am
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.

Re: Editing Basic code

Posted: Thu Dec 20, 2018 2:46 pm
by Philip Stott
Thanks for the help.

It is definitely Windows 10. I loaded OO on a Windows 7 machine and it works perfectly

Re: Editing Basic code

Posted: Thu Dec 20, 2018 3:46 pm
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.

Re: Editing Basic code

Posted: Thu Dec 20, 2018 5:31 pm
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.

Re: Editing Basic code

Posted: Thu Dec 20, 2018 5:41 pm
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

Re: Editing Basic code

Posted: Sun Dec 23, 2018 5:15 am
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 ?

Re: Editing Basic code

Posted: Sun Dec 23, 2018 9:19 am
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

Re: Editing Basic code

Posted: Sun Dec 23, 2018 8:35 pm
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

Re: Editing Basic code

Posted: Sun Dec 23, 2018 8:41 pm
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

Re: Editing Basic code

Posted: Sun Dec 23, 2018 9:13 pm
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.

Re: Editing Basic code

Posted: Sun Dec 23, 2018 11:08 pm
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...