[Solved] Searching in a textbox

Discuss the database features
Post Reply
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

[Solved] Searching in a textbox

Post by RPG »

Hello

History
Long time ago there was a question on the old OOo forum for selecting a word in a long textbox in a form. My knowledge about the API was not enough to find a good solution. The first problem for me was searching in a textbox and later I could not find a good solution for making a selecting in the textbox. When I had opened the form then the selection did work but this not always when I did it more times again. Now I hope I have a solution for all problems. I did found a property on the text what is called: HideInactiveSelection. The property can also be set direct on the textbox without macro. I did not search on that place for the property but I did search in the document properties. Now I'm happy.

The [Solved] find and highlight text or string in forms is solved with a workaround and I hope this works better.

Not all comments are in English. The reason is I did not know when I started to make this public.


Explanation
I believe this is a good working code. The small example demonstrate only how you can search in a textcontrol. I have stripped as much as possible to show how it is working. The result is a example for one control and the Dutch text in the example. I believe this can be used in a samll form. For me own I use code what makes a list of alle the words in a field. I put this words in a table in which I can search. The list of words is combination of a word and a record.This works for the HSQLDB database and maybe for more.

HideInactiveSelection
When you make your own form then take care you set the property Hide Selection to no. This is aproperty of the textbox and not of the form.

Romke
Attachments
VoorbeeldKaarten07.odt
How to search in a textbox in a form
(23.15 KiB) Downloaded 362 times
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
platon
Posts: 2
Joined: Wed Dec 02, 2009 1:38 am

Re: [Solved] Searching in a textbox

Post by platon »

Hello Romke, I am still using the code you gave me three years ago and the new version looks a lot simpler. But I cant seem to get it to work with my form - I understand macros too little even to know which terms to replace with my form-names etc. But maybe the problem is just that Im still using Ooo 3.3 rather than Libre office. I'll try and work myself into it later. Thanks for improving the usability thus, I hope this will be implemented as a normal feature one day...

Platon
OOo 3.3.1 on XPpro
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: [Solved] Searching in a textbox

Post by RPG »

Hello

First I'm glad you did find this and can use it.

I believe this kind of searching can be used with all version of OOo higher then OOo 2.1 but I can not be sure.

When it is difficult for you to adjust it to your needs then come with questions. My purpose is also people can use this kind of code without understanding it complete.

How to use this example
I think use the form as it is now. I think use it first as a standalone form. You can change the properties in the data forms. Data forms are what you see in the form navigator. I believe you can use an other querie in the form navigator but don't change the name of the properties of big control. You can change the color or size but not data field name or name of the control. But this is not a big problem in the query you can give an alias name to the fieldname you need. When you can use first the small example then errors can be point to a small part. In the complete example I do use BASIC macros and also SQL code executed with BASIC macros.


The complete example
I have also placed the complete code with all forms and controls but I believe here are to much bleeding edges for using it to other people. When you or persons do like it you may use it and I will try to answer questions. I will warn this is complicated code and not easy to understand but I have a hope it is usable for an other databases with only using good views.

The script file to the database

Code: Select all

CREATE SCHEMA PUBLIC AUTHORIZATION DBA
CREATE MEMORY TABLE "RealTable"("ID" INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"Date" DATE DEFAULT CURRENT_DATE,"Title" VARCHAR_IGNORECASE(50),"Categorie" VARCHAR_IGNORECASE(50) DEFAULT '',"CategorieSub" VARCHAR_IGNORECASE DEFAULT '',"Memofield" VARCHAR_IGNORECASE(2147483647))
CREATE MEMORY TABLE "informatie"("id" INTEGER NOT NULL PRIMARY KEY,"Onderwerp" VARCHAR_IGNORECASE(100),"urladres" VARCHAR_IGNORECASE(100),"opmerkingen" VARCHAR_IGNORECASE(100),"forum" VARCHAR_IGNORECASE(100),"nog1" VARCHAR_IGNORECASE(100),"nog2" VARCHAR_IGNORECASE(100),"getal" INTEGER,"getal1" INTEGER)
CREATE CACHED TABLE "woordenlijst"("id" INTEGER NOT NULL,"woorden" CHAR NOT NULL,CONSTRAINT "precies" PRIMARY KEY("id","woorden"),CONSTRAINT SYS_FK_945 FOREIGN KEY("id") REFERENCES "RealTable"("ID") ON DELETE CASCADE ON UPDATE CASCADE)
CREATE MEMORY TABLE "ZW"("woorden" VARCHAR(100) NOT NULL PRIMARY KEY)
CREATE MEMORY TABLE "begin"("woor" VARCHAR_IGNORECASE(100) NOT NULL PRIMARY KEY)
CREATE MEMORY TABLE "uitkomst"("teller" INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"id" INTEGER,"woorden" VARCHAR_IGNORECASE,CONSTRAINT SYS_FK_948 FOREIGN KEY("id") REFERENCES "RealTable"("ID") ON DELETE CASCADE ON UPDATE CASCADE)
CREATE MEMORY TABLE "uitkomstComboSearch"("ID" INTEGER NOT NULL PRIMARY KEY,"Categorie" VARCHAR_IGNORECASE(100),"cat2" VARCHAR_IGNORECASE(100),"Onderwerp" VARCHAR_IGNORECASE(100))
CREATE MEMORY TABLE "nieuw"("woorden" CHAR NOT NULL PRIMARY KEY)
CREATE MEMORY TABLE "uitkomst2"("id" INTEGER)
SET TABLE "woordenlijst" INDEX'488032 488032 0'
ALTER TABLE "RealTable" ALTER COLUMN "ID" RESTART WITH 1
ALTER TABLE "uitkomst" ALTER COLUMN "teller" RESTART WITH 1
CREATE VIEW "Datatable" ("ID","Date","Title","Categorie","CategorieSub","Memofield") AS SELECT \u000a  "ID",\u000a  "Date", \u000a  "Title",\u000a  "Categorie",\u000a  "CategorieSub",\u000a  "Memofield" \u000aFROM \u000a  "RealTable" AS "RealTable"
CREATE USER SA PASSWORD ""
GRANT DBA TO SA
SET WRITE_DELAY 60
SET SCHEMA PUBLIC
 Edit: I did get a PM what makes clear there is no connection possible to the database. The solution is
I don't know what the reason is for the problem but maybe the next can be a solution for you: make a connection to the hsqldb.jar.

You can do in the folowwing way.

menu --> tools -->options

In the next popup goto
OpenOffice.org --> java --> Class path

In the next popup
add archive and search then the file you need in my case in is:
/usr/lib/ooo3/basis3.2/program/classes/hsqldb.jar


There I have a linux version it can maybe the same for you. but for window users the start is a little else but they have to search the file.

I hope this is working. It is not clear to me why you need it but I have to use the same for me most of the time.
I think use it only as a tempory solution on your system there when you create a new database you have to use it again for the new database. 

Romke
Attachments
kaarten2.odb
This is the database how I use it. There are no tables
(120.01 KiB) Downloaded 345 times
Last edited by RPG on Thu Mar 08, 2012 4:34 pm, edited 1 time in total.
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: [Solved] Searching in a textbox

Post by RPG »

Hello
I have add below a step by step instruction for how to use this in a other database. I have test it and it did work for me.

Step 1

Code: Select all

Open the example
goto the macro's
Select the Organizer
Select the tabpage "Libraries
Select your document in this case the example.
Select the library Kaarten
Click on the button Export
Select the option for BASIC
Select the place where you want store the library and give a name.

Step 2

Code: Select all

a) Make a control for inputting the search term
b) Imput the library
b1 goto macro's
b2 goto the organizer
b3 goto the library tab
b4 select the program in which you want insert the library
b5 do import the library by selecting the library on the disk
c) Make a button
d) Connect the button to the sub SearchWithDialog in the library "kaarten"

CHange to make in the macro code
e) When you push the button then you get three times an error You must give there the names of the forms or the names of the text box.

f)Then when the dialog is started and when you search for a word then you have to change the name for the textbox in which you want search, 

Change to make in the form
g) The property "Hide selection "  of the control in which you want select words must be set to NO
I believe now it can work

It does not work when you restart your form.
When your form is loaded then there must be an event of the form document to a macro loading the library Kaart. Set this event for the form document
menu --> tools --> Customize

goto tabpage events.

I think it can be good to copy the macro by hand.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: [Solved] Searching in a textbox

Post by RPG »

Hello

I did make a new example with the same code. Now I have to move the variables you have to change in the beginning of the modules. I have them changed to constant variable with comments to it. I also have delete a lot of code. So I hope it is more easy to understand.

Romke
Attachments
VoorbeeldKaarten09.odt
Nearly the same as the first file
(22.02 KiB) Downloaded 330 times
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Post Reply