OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Solved] Setting the text in a form control - setText()?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Toto1919
Power User
Power User


Joined: 29 Nov 2007
Posts: 53
Location: Lithuania

PostPosted: Mon Jan 07, 2008 11:45 am    Post subject: [Solved] Setting the text in a form control - setText()? Reply with quote

Hi, I need some help.

I have tried the following, and it works fine to retrieve the values from the two 'account' fields, but I can't set the value in the 'Sum_of_account' field.

Code:
Sub SumAccounts
    dim oDoc
    dim oForm
    dim oCtl
    dim x as variant
    dim sumx as variant
     
    oDoc = ThisComponent
    oForm = oDoc.DrawPage.Forms.GetbyIndex(0)
     
    oCtl=oForm.GetByName("account1")
    x = oCtl.CurrentValue
    sumx = sumx + x
    oCtl=oForm.GetByName("account2")
    x = oCtl.CurrentValue
    sumx = sumx + x
    oCtl=oForm.GetByName("Sum_of_account")
    oCtl.CurrentValue = sumx      *** This doesn't work ***
End Sub


I have also tried...

Code:
oCtl.setText(sumx)


... but it doesn't work either. Could someone please tell me how to modify this row to be able to show the sum (sumx) in the 'Sum_of_account' field?

O yeah, I should probably mention also that all the three form fields are 'formatted fields'.

Thomas


Last edited by Toto1919 on Mon Jan 07, 2008 11:28 pm; edited 1 time in total
Back to top
View user's profile Send private message
QuazzieEvil
Super User
Super User


Joined: 17 Jan 2007
Posts: 599
Location: Houston, TX

PostPosted: Mon Jan 07, 2008 12:21 pm    Post subject: Reply with quote

what exactly is not working? is the string not being writen to the control? or not saved to the database?

EDIT:

to set the control value you can use the Text property --SumControl.Text=TheSum

however, this will not write the new value to the database--in case the sum control is bound to a table column.

in this case, update the corresponding column:

Form.Columns.getByName("SUMCOLUMN").updateDouble(TheSum)

--assuming the column to which this control is bound is called SUMCOLUMN
Back to top
View user's profile Send private message Visit poster's website
Toto1919
Power User
Power User


Joined: 29 Nov 2007
Posts: 53
Location: Lithuania

PostPosted: Mon Jan 07, 2008 11:23 pm    Post subject: Reply with quote

No, I don't have a database. Just a form with some form control fields on it.

Thanks alot. I tried setText() and a number of other things but your solution worked. Thank you!

Final code:
Code:
Sub SumAccounts
    dim oDoc
    dim oForm
    dim oCtl
    dim x as variant
    dim sumx as variant
     
    oDoc = ThisComponent
    oForm = oDoc.DrawPage.Forms.GetbyIndex(0)
     
    oCtl=oForm.GetByName("account1")
    x = oCtl.CurrentValue
    sumx = sumx + x
    oCtl=oForm.GetByName("account2")
    x = oCtl.CurrentValue
    sumx = sumx + x
    oCtl=oForm.GetByName("Sum_of_account")
    oCtl.Text = sumx
End Sub


Thomas
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group