Vieri , pleasqe find some working code below hope it helps:so every field has a "Placeholder" property who correspondents with the data who commes here from a beamer
Dim aTextFields as Object Dim i as integer Dim CurElement as Object 'xray.xray oDocument aTextfields = oDocument.getTextfields.CreateEnumeration While aTextFields.hasmoreElements' CurElement = aTextField.NextElementIf CurElement.PropertySetInfo.hasPropertybyName("PlaceHolder")Then
If (CurElement.PlaceHolder = "Lezers") Then CurElement.getAnchor.setString(sLezers) ElseIf (CurElement.PlaceHolder = "Mag") Then CurElement.getAnchor.setString(sNaam) ElseIf (CurElement.PlaceHolder = "Half") Then CurElement.getAnchor.setString(sHalf) Elseif (CurElement.PlaceHolder = "Voll") Then CurElement.getAnchor.setString(sVoll) Elseif (CurElement.PlaceHolder = "pr1") Then CurElement.getAnchor.setString(sPr1) Elseif (CurElement.PlaceHolder = "prH") Then CurElement.getAnchor.setString(sPrH) Elseif (CurElement.PlaceHolder = "prV") Then CurElement.getAnchor.setString(sPrV) Elseif (CurElement.PlaceHolder = "advprijs1") Then CurElement.getAnchor.setString(sadvprijs1) Elseif (CurElement.PlaceHolder = "ipvprijs1") Then CurElement.getAnchor.setString(sipvprijs1) Elseif (CurElement.PlaceHolder = "1jaargang") Then CurElement.getAnchor.setString(s1jaargang) Elseif (CurElement.PlaceHolder = "btw6_1") Then CurElement.getAnchor.setString(sbtw6_1) Elseif (CurElement.PlaceHolder = "totaal1") Then CurElement.getAnchor.setString(stotaal1) Elseif (CurElement.PlaceHolder = "advprijs2") Then CurElement.getAnchor.setString(sadvprijs2) Elseif (CurElement.PlaceHolder = "ipvprijs2") Then CurElement.getAnchor.setString(sipvprijs2) Elseif (CurElement.PlaceHolder = "2jaargang") Then CurElement.getAnchor.setString(s2jaargang) Elseif (CurElement.PlaceHolder = "btw6_2") Then CurElement.getAnchor.setString(sbtw6_2) Elseif (CurElement.PlaceHolder = "totaal2") Then CurElement.getAnchor.setString(stotaal2) Endif End if Wend Endif
Thanks! Making progress... finally. Your code actually retrieved the text within my first "text box" (which is at least something!) but then it fails with the error: LibreOffice 4.0.2.2 BASIC runtime error. '423' Text it points to line: Print x.getName() & " : " & x.Text It may be choking on a "formatted field" within the document. Just out of curiosity, how did you know that you had to use ThisComponent.DrawPage.Forms? As a novice, I find the documentation to be quite confusing and a supposedly "simple" task such as getting text field values seems to be quite difficult. I mean, I found examples on the net and they all start with something like: vEnum = ThisComponent.getTextFields().createEnumeration() If Not IsNull(vEnum) Then Do While vEnum.hasMoreElements() vVal = vEnum.nextElement() but then I either don't know how to continue or the examples I found on the net don't work (maybe outdated OO or LO versions). BTW, is there an IDE that can auto-complete Basic code (eg. vVal.??? as in the example above). Thanks, Vieri --- On Wed, 5/8/13, mcmurchy1917-libreoffice@yahoo.co.uk <mcmurchy1917-libreoffice@yahoo.co.uk> wrote:I've created two "Text Boxes" in a form in a writer document. I can iterate over them like this grabbing the text as I go Sub EnumerateFields oDoc = ThisComponent oDrawPage = oDoc.DrawPage oForm = oDrawPage.Forms.GetByIndex(0) For i = 0 To oForm.getCount()-1 x = oForm.getByIndex(i) Print x.getName() & " : " & x.Text NextEnd SubDoes this help in anyway? Iain On Wednesday 08 May 2013 01:50:02 Vieri wrote:--- On Tue, 5/7/13, Vieri <rentorbuy@yahoo.com>wrote:--- On Mon, 5/6/13, Andrew Douglas Pitonyak <andrew@pitonyak.org> wrote:On 05/06/2013 05:21 AM, Vieri wrote:Hi, I have an odt writer document with 2input textfields(added with the form designer toolbar). Imanually typetextinto one of the fields. I copy/pasted a macroto see ifIcould grab the text within the input fieldbut haven'thadany luck. This is the test macro in Basic:Sub EnumerateFields vEnum =ThisComponent.getTextFields().createEnumeration()If Not IsNull(vEnum) Then IfvEnum.hasMoreElements() ThenPrint "OK" Else Print "NOTOK"End If End If End Sub If I manually run this macro I get the"NOT OK"message.What am I doing wrong? What is the correct way of getting thetext fieldelements?Thanks VieriI grabbed these two routines from my testmoduleswithoutrunning them first....Hi, Thanks for the reply but I'm still havingtrouble.I'm either way off-course, misusing LO or making adumbrookie mistake. I copied your macros to my odt document. I then did a "tools, macros, run macro..." andselected theSubs I copied. If I run EnumerateTextFields then it yields the"Finished"message box (nothing else). If I run DisplayMasterFields then it yields thefollowingmessage: ===Text Field Masters===(com.sun.star.text.fieldmaster.SetExpression.Illustration,Illustration) (com.sun.star.text.fieldmaster.SetExpression.Table,Table) (com.sun.star.text.fieldmaster.SetExpression.Text,Text) (com.sun.star.text.fieldmaster.SetExpression.Drawing,Drawing)My odt document has 2 input fields in a form. By the way, if I place a button within my form andconfigurethe "Mouse button pressed" to launch, say, EnumerateTextFields then I get the following errormessage:"LibreOffice 4.0.2.2 BASIC runtime error. '423' getTextFields" and it points at the line: "oEnum =oDoc.getTextFields().createEnumeration()"I'm stuck on something that should be quitesimple.I'm attaching my odt file hoping that someone cantell mewhat novice mistake I'm making.Trying to attach the file again but it seems that themailing list strips itout. Thanks, Vieri-- To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/ Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette List archive: http://listarchives.libreoffice.org/global/users/ All messages sent to this list will be publicly archived and cannot be deleted
-- To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/ Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette List archive: http://listarchives.libreoffice.org/global/users/ All messages sent to this list will be publicly archived and cannot be deleted