Ask Your Question
1

get text field value [closed]

asked 2013-05-03 13:28:32 +0100

VDP gravatar image

Hi,

I have an odt writer document with 2 input text fields (added with the form designer toolbar). I manually type text into one of the fields. I copy/pasted a macro to see if I could grab the text within the input field but haven't had any luck. This is the macro in Basic:

REM Author: Heike Talhammer
REM Modified: Andrew Pitonyak
Sub EnumerateFields
  Dim vEnum
  Dim vVal
  Dim s1$, s2$
  Dim sFieldName$, sFieldValue$, sInstanceName$, sHint$, sContent$

  vEnum = thisComponent.getTextFields().createEnumeration()
  If Not IsNull(vEnum) Then
    Do While vEnum.hasMoreElements()
      MsgBox "In loop"
      vVal = vEnum.nextElement()
      If vVal.supportsService("com.sun.star.text.TextField.Input") Then
        sHint=vVal.getPropertyValue("Hint")
        sContent=vVal.getPropertyValue("Content")
        s1=s1 &"Hint:" & sHint & " - Content: " & sContent & chr(13)
        'change the content
        vVal.setPropertyValue("Content", "My new content")
        ThisComponent.TextFields.refresh()
      End If

      If vVal.supportsService("com.sun.star.text.TextField.User") Then
        sFieldName  =vVal.textFieldMaster.Name
        sFieldValue = vVal.TextFieldMaster.Value
        sInstanceName= vVal.TextFieldMaster.InstanceName
        s2 = s2 & sFieldName & " = " & sFieldValue & chr(13) & "InstanceName: " & sInstanceName & chr(13)
        'new value for textfield
        vVal.TextFieldMaster.Value=25 
      End If
    Loop
    MsgBox s1, 0, "=== Input Fields ==="
    MsgBox s2, 0, "=== User Fields ==="
  End If
  ThisComponent.TextFields.refresh()
End Sub

When I run this macro I just get 2 blank message boxes with the titles "=== Input Fields ===" and "=== User Fields ===". (the message "In loop" is NOT displayed)

What am I doing wrong?

Thanks

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-03-06 14:18:35.412715

1 Answer

Sort by » oldest newest most voted
0

answered 2014-11-18 06:47:15 +0100

MQ-818 gravatar image

CHANGE 1

DO While vEnum.hasMoreElements()

DO

CHANGE 2

LOOP

LOOP While vEnum.hasMoreElements()

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-03 13:28:32 +0100

Seen: 1,969 times

Last updated: Nov 18 '14