[Solved] Spell Check Base TextBox

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
echo8hink
Posts: 12
Joined: Wed Mar 02, 2016 7:59 pm

[Solved] Spell Check Base TextBox

Post by echo8hink »

I have worked up a Base macro application that lets me spell check a text box in OpenOffice and LibreOffice Base. I'd like to put it up here as a demo .odb, for use as desired. I know there are some who dislike macro solutions for a variety of good reasons, but I think this feeble app is useful if you have text box entries that need a quick spell check. I will accept any feedback provided. I can always learn from the experienced members here.

If this works for others as it does for me, maybe some user refinements will make it even better. Sample .odb

Dave
Attachments
SpellCheckBASEwMacros.odb
Spell check text box in Base with macros.
(20.4 KiB) Downloaded 303 times
Last edited by Hagar Delest on Sat Jan 21, 2017 3:18 pm, edited 1 time in total.
Reason: tagged [Solved].
LibreOffice 5.4.5.1 on Linux Mint 18.3
User avatar
Villeroy
Volunteer
Posts: 31349
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Spell Check Base TextBox

Post by Villeroy »

Thank you. This is very useful for a lot of users who store human language in databases. I added the ability to spell check other languages.
Put some locale string like en-US, de-DE into the additional info field of the text box. I made the string comparison case-insensitive. en-gb works as well as en-GB.

3 changes to the code:
1. remove type declaration for aLocale so it becomes Variant
2. below the vSpeller declaration:

Code: Select all

  Dim vSpeller As Variant
  vSpeller = createUnoService("com.sun.star.linguistic2.SpellChecker")
  aLocale = getExistingLocale(vSpeller, oControl.Tag)
	if not isUnoStruct(aLocale) then
		msgbox("No spell check magic availlable for "& oControl.Tag, 48, "macro:SpellCheckWordsArray")
		exit sub
	endif
3. append 2 functions:

Code: Select all

Function getExistingLocale(srv, sloc)
Dim a(), alc, i, lc
lc = getLocaleStruct(sloc)
a() = srv.getLocales()
for i = 0 to uBound(a())
	alc = a(i)
	if strComp(lc.Language, alc.Language, 0) _
		+ strComp(lc.Country, alc.Country, 0) _
		+ strComp(lc.Variant = alc.Variant, 0) = 0 then 
		getExistingLocale = alc : Exit For
	endif
next
End Function

Function getLocaleStruct(s)
Dim lc, a()
	lc = createUnoStruct("com.sun.star.lang.Locale")
	a() = split(s, "-")
	lc.Language = a(0)
	if uBound(a())>0 then lc.Country = a(1)
	if uBound(a())>1 then lc.Variant = a(2)
	getLocaleStruct = lc
End Function
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
Posts: 31349
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Spell Check Base TextBox

Post by Villeroy »

Further changes: Added the locale info to the input box and made an extension.
Usage:
1. Create a push button with the text box name as "additional info".
2. Assign SpellCheckBase.Module1.SpellCheckTextString to the button's "Execute" or "Mouse released" event.
2. Add the locale name as "additional info" to the text box.
Attachments
SpellCheckBase.oxt
Installer for Basic library "SpellCheckBase"
(4.71 KiB) Downloaded 226 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
JeJe
Volunteer
Posts: 3119
Joined: Wed Mar 09, 2016 2:40 pm

Re: Spell Check Base TextBox

Post by JeJe »

I've been working on something similar... attached...

Code is a mess, unfinished and uncommented etc... I'm just posting as might help you here - you're welcome to use any of it.

Intention is to create most of the functionality of a main document window for any textfield via an extension. (Spell/thes/autocomplete/autocorrect/autotext).
I flit around between different projects. When I get there...
Attachments
Spelling Thesaurus Dialog textboxes.odt
(22.88 KiB) Downloaded 237 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Villeroy
Volunteer
Posts: 31349
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Spell Check Base TextBox

Post by Villeroy »

Indeed, you can do a lot more good looking stuff with the dialogs. But limiting the language to the single western language found in the global options is not enough. One use case for databases are vocabularies for learners.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
echo8hink
Posts: 12
Joined: Wed Mar 02, 2016 7:59 pm

Re: [Solved] Spell Check Base TextBox

Post by echo8hink »

Thanks Villeroy, for the very nice touch to make the spell check available to other language uses. I could not have done it.

My sister translates English/Spanish contract documents and thinks she may be able to use this feature on standard contract paragraphs for her work. Nice.

As an update, I have only made a minor change in my experience using the spell check code. I surrounded the "Replace()" function code with a conditional that only does an update if the text requires a change. Then a minor adjustment of the replacement itself, based on the optional arguments of the function.

Code: Select all

If sSelSpell <> s(i) Then
 	' if the Input text is not the same as the original word and requires update of TextBox text
        ' replace misspelled word in text with contents of Input box...
        '
        ' option to not replace ALL occurances on first find. Limit to just first (current) one...
        '	Replace() last three args: start char, times to replace, case sensitive 0=yes 1=no
        sTextFromBox = Replace(sTextFromBox, s(i), sSelSpell,1,1,0 )
        ' finally, update the textbox text
        oControl.BoundField.updateString(sTextFromBox)
End If
I have also learned that the ALL CAPS spell checking is controlled by a setting in the Tools->Options->Language options. Therefore, the LCase() function could be removed from the spelling check code. It makes little difference. It may keep some proper nouns out of the misspell list such as: "andrew" for "Andrew"

Thanks again for all you do. I have been running my recipes db in your split mode setup for almost two years now.
LibreOffice 5.4.5.1 on Linux Mint 18.3
Post Reply