Drew Jensen wrote:
Hello John, Marc, Barbara, et al.

This is part one of a possible answer to the question as I rephrased it.

How to remove trailing white space from a text field?

Simply put you will need to use some procedural language to do this.

I chose to use OO.oBasic for the moment.

Part two will be on how to call this function for each record in a table.

Well I decided to make a part 1.5 before part 2..

Simply - you will find an attached file here:
StripWhiteSpace.odb

This embedded database has 1 table, "Table1", with 2 fields, "ID" and "txt".

It has one form, "Table1", with 3 controls. 2 text boxes and a button.

The form also has an attached basic library, with the functions I included in the last email.

Two more procedures where added.
onLoad - this is called when the form is opened and ensures that the TOOLS library is available. CleanThisData - which is called when the Button is clicked and cleans the contents of the text control bound to the "txt" column.

sub CleanThisData( oEv as object )
 dim oDataBaseForm as object
 dim oTextBoxModel as object
 dim oTextBoxControl as object

 oDataBaseForm = oEv.source.Model.Parent
 oTextBoxModel = oDataBaseForm.getByName( "txttxt" )
oTextBoxControl = thisComponent.CurrentController.getControl( oTextBoxModel )
 if oTextBoxModel.Text <> "" then
   oTextBoxControl.Text = RTrimWhiteSpace(oTextBoxModel.Text)
 end if
end sub


@John - I decided to post this up first because I'm assuming that what you are doing is gathering data via cut-n-paste from such things as pdf files and web sites. This is the reason for the extra characters at the end of the data. If you can follow along, all you need do is:
Load your database
Load this database
In the macro editor copy the code form the form in this example database to a library attached to your form. Add a button to your form that you then attach to your copy of the CleanThisData procedure and change the line of code:

 oTextBoxModel = oDataBaseForm.getByName( "txttxt" )

to use the name of the control on your form that you paste data into. Do this and you can clean up your data as you enter it.

Also, if you have questions about doing this then we can cover them now - before I put up an example that fixes up your existing data.

Till later,

Drew

Attachment: StripWhiteSpace.odb
Description: application/vnd.oasis.opendocument.database

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to