[Solved] Use Dialog Control to change Form Controls

The Application Programming Interface and the OASIS Open Document Format

[Solved] Use Dialog Control to change Form Controls

Postby Tobin » Sun Feb 08, 2009 6:58 pm

Howdy,

I'm new to the OO Basic API. I am sure you will be able to tell :) . Anyway - what I'm trying to do is - use my Start control button on the Dialog to access, and change, the Form Control buttons. I have attached the .ods file I'm trying to work with. I've done some research and trial-and-error but can't seem to figure it out.

Can anyone show me how to do this? You may change anything in the Start macro found in the attached .ods file and return it.

Thanks

UPPERLEVEL2.ods
(19.92 KiB) Downloaded 268 times
Last edited by Tobin on Sat Feb 14, 2009 10:08 pm, edited 1 time in total.
Tobin Sparks
OOo 3.0, XP
Houston, Texas USA
OOo 3.0.X on Ms Windows XP
Tobin
 
Posts: 35
Joined: Sun Feb 08, 2009 3:31 am
Location: Houston, Texas USA

Re: Use Dialog Control to change Form Controls

Postby FJCC » Mon Feb 09, 2009 5:07 am

Here is a modified version of your sub Start. It toggles the "Item 1" button between Enabled = True and Enabled = False with an artificial wait in between. When your dialog button calls the Start routine the Form button will be modified. If you don't have tools like XRay or MRI to examine objects, I suggest you get one. It makes life much easier. You can find them here: XRay MRI
Code: Select all   Expand viewCollapse view
sub Start

rem ----------------------------------------------------------------------
rem define variables
Dim vButton as Object
Dim vForms, Form as Object

vForms = ThisComponent.CurrentController.ActiveSheet.DrawPage.Forms

'Form = vForms.getByIndex(0)   'Alternate method
Form = vForms.getByName("Standard")
vButton = Form.getByName("btn_Item1")
vButton.Enabled = True
Print "Wait"
vButton.Enabled = False

end sub
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7490
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Use Dialog Control to change Form Controls

Postby Tobin » Mon Feb 09, 2009 4:07 pm

Howdy FJCC,

Your post is very helpful to me. I have downloaded X-Ray and MRI and will try to figure out how to use them.

Thanks Again
Tobin Sparks
OOo 3.0, XP
Houston, Texas USA
OOo 3.0.X on Ms Windows XP
Tobin
 
Posts: 35
Joined: Sun Feb 08, 2009 3:31 am
Location: Houston, Texas USA

Re: Use Dialog Control to change Form Controls

Postby Tobin » Mon Feb 09, 2009 10:59 pm

Howdy,
Okay - Well - after working with the above method for accessing and changing the button.enabled property, I need to refine my question ;) . The above method gets the button object thru the View structure (I'm assuming that is what the "v" prefix is on the variables), which is a good way to do it. But, I'm also going to want to try to use the Form buttons TabIndex numbers to allow the user to move thru the Form buttons by using the Dialog buttons "Back" and "Next".
So - apparently I'll have to access the form buttons thru the Model structure.
<model.Name(String); model.enabled(Boolean); model.TabIndex(Long), etc.>

Could someone help me with this - Please?
Tobin Sparks
OOo 3.0, XP
Houston, Texas USA
OOo 3.0.X on Ms Windows XP
Tobin
 
Posts: 35
Joined: Sun Feb 08, 2009 3:31 am
Location: Houston, Texas USA

Re: Use Dialog Control to change Form Controls

Postby Tobin » Tue Feb 10, 2009 2:29 am

Howdy,

OOPS - It was so simple. Thanks Again for your help. But I'm still curious - is there a way to use the model Object to do this instead of the View Object?

Any help would be appreciated
' ----------
Sub Start

rem define variables
Dim vButton, vForms, Form as Object
Dim i as Integer

vForms = ThisComponent.CurrentController.ActiveSheet.DrawPage.Forms

'Form = vForms.getByIndex(0) 'Alternate method
Form = vForms.getByName("Standard")
vButton = Form.getByName("btn_Item4")

vButton.Enabled = False
MsgBox "Wait", 64
vButton.Enabled = True

i = vButton.TabIndex
MsgBox("The TabIndex = " & i, 64)

End Sub
' ----------
Thanks
Tobin Sparks
OOo 3.0, XP
Houston, Texas USA
OOo 3.0.X on Ms Windows XP
Tobin
 
Posts: 35
Joined: Sun Feb 08, 2009 3:31 am
Location: Houston, Texas USA

Re: Use Dialog Control to change Form Controls

Postby FJCC » Tue Feb 10, 2009 3:15 am

The object Form has the property ControlModels which is an array of models and Form has a method getControlModels. So you can make an array of models with
Models() = Form.getControlModels
You can then, for example, access the model for the button labeled Item 2 with the statement buttonModel = Models(1) Models() is indexed from 0, so Item 1 has the index 0 etc. Your Back and Next buttons can increment the index of Models() to access whatever button model you want.
This is a good place to practice with XRay or MRI as they help you find the properties and methods of the control models much more easily than the official documentation.

The prefixes on variables are used to indicate the type. Objects start with o, strings with s and so on. This is just a naming convention and has no effect within the code. The v prefix is for variant, if I remember correctly
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7490
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Use Dialog Control to change Form Controls

Postby Tobin » Tue Feb 10, 2009 3:31 am

FJCC,

Thanks for your reply. You've been very helpful. I'll spend some time going over your post and getting used to MRI. I had an error when starting X-Ray, maybe it's not ready for OOo 3.0 yet. I was forgetting OOo Basic Defaults to data type Variant. I started thinking prefix "o" was for OpenOffice and "v" was for View Object. DAA! Thanks for straightening me out :) .

Thanks Again
Tobin Sparks
OOo 3.0, XP
Houston, Texas USA
OOo 3.0.X on Ms Windows XP
Tobin
 
Posts: 35
Joined: Sun Feb 08, 2009 3:31 am
Location: Houston, Texas USA


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 2 guests