Ask Your Question
0

Basic statement to assign a value to a form control gives error msg

asked 2016-07-25 04:42:14 +0200

stroy gravatar image

"BASIC runtime error. An exception occurred Type: com.sun.star.lang.IllegalArgumentException Message: arguments len differ!." Both type Integer--any suggestions? I'm trying to select an item from a list box and transfer that value to a field in a table. Code follows: Option Explicit Global oForm, oControl As Object Global ShowInt as Integer

Sub SetControlStr(FrmNam, CntrlNam, NewStr As String) oForm = ThisComponent.DrawPage.Forms.GetByName(FrmNam) oControl = oForm.GetByName(CntrlNam) oControl.SetPropertyValue(NewStr) End Sub

Sub SetControlInt(FrmNam, CntrlNam As String, NewInt As Integer) oForm = ThisComponent.DrawPage.Forms.GetByName(FrmNam) oControl = oForm.GetByName(CntrlNam) oControl.SetPropertyValue(NewInt) End Sub

Sub ExecuteAction_AccountListBox oForm = ThisComponent.DrawPage.Forms.GetByName("LogQueryForm1") oControl = oForm.GetByName("lstAccountListBox") ShowInt = oControl.ValueItemList(oControl.SelectedItems(0)) MsgBox ShowInt,0,"AccountListBox" 'Just for debugging IF ShowInt = 1 Then 'New Account Call SetControlStr("LogQueryForm1", "fmtAccountID", "") Call SetControlStr("LogQueryForm1", "txtAccountCompany", "") Call SetControlStr("LogQueryForm1", "txtAccountNbr", "") Call SetControlStr("LogQueryForm1", "txtAccountTyp", "") Call SetControlStr("LogQueryForm1", "txtAcctDescrit", "")
Else 'Transfer list AccountID to AcctID Call SetControlInt("LogQueryForm1", "fmtAcctID", ShowInt) ' <-- Error comes here EndIf End Sub

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2016-07-25 06:44:30 +0200

Ratslinger gravatar image

First, please learn how to use the controls for preformatted text. Your question was difficult at best to read.

Sub SetControlInt(FrmNam, CntrlNam As String, NewInt As Integer)
  oForm = ThisComponent.DrawPage.Forms.GetByName(FrmNam)
  oControl = oForm.GetByName(CntrlNam)
  oControl.SetPropertyValue(NewInt)
End Sub

setPropertyValue doesn't know what value you are setting. There are many properties for a control. What you want is:

 oControl.Text = NewInt

Now this depends upon what you are going to do with this control. If it is going to be used to update a table it won't work. In this case you must use the View of the control:

Sub SetControlInt(FrmNam, CntrlNam As String, NewInt As Integer)
    Dim CtlView as Object
    Dim DocCtl as Object
    oForm = ThisComponent.DrawPage.Forms.GetByName(FrmNam)
    oControl = oForm.GetByName(CntrlNam)
    DocCtl = ThisComponent.getCurrentController()
    CtlView = DocCtl.getControl(oControl)
    CtlView.Text = NewInt
 End Sub

Then you must actually tab through the field for it to be accepted for an update.

edit flag offensive delete link more

Comments

1) Thanks, Ratslinger! Your code works exactly as you describe. 2) Regarding "preformatted text" issue with the code: I'm using Mac, OS X 10.11.6, Firefox 47.0.1, and Libreoffice 5.1.4.2. I cut the code out of the Libreoffice macro editor, and pasted it into the ask.libreoffice question window. It was beautifully formatted in the macro editor, and in the question window. Then when I pressed the "Submit" button it showed as all run together. Is there a way to prevent this?

stroy gravatar imagestroy ( 2016-07-26 03:41:13 +0200 )edit

Note: exactly the same happened to the above comment. I had comment (1) and (2) on separate lines, separated by a blank line.

stroy gravatar imagestroy ( 2016-07-26 03:42:32 +0200 )edit

As far as the text, it appears you didn't use the toolbar icon for inserting the text. You can see in my answer the gray boxes the code is in. Also I believe there is a preview window where you can view you input as it will be displayed.

Ratslinger gravatar imageRatslinger ( 2016-07-26 18:20:36 +0200 )edit

OK, thanks again! I see an icon that says 101 010, and hovering the mouse it says "preformatted text" -- didn't know what that was for.

stroy gravatar imagestroy ( 2016-07-26 20:55:59 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-07-25 04:42:14 +0200

Seen: 235 times

Last updated: Jul 25 '16