[Solved] Get Text value from text box on dialog

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
cdub
Posts: 7
Joined: Tue Mar 18, 2008 4:41 am

[Solved] Get Text value from text box on dialog

Post by cdub »

Ubuntu 7.10 OOo 2.3

Spent a few hours trying to do the following simple macro.

on running the macro, a dialog pops up with some text fields the user fills in. The user the clicks a "run" button, and the macro does its thing.

The dialog and controls are created (and given meaningful names).
Running the macro brings up the dialog automatically.
Clicking the "RUN" button fires off a second macro that is supposed to do the work

what I can't do is get the values the user input into the text boxes.

So, the dialog is up, and the user has entered a value into a text box called txt_SrcCol.
The user pushes Run, which is linked to this subroutine.

For test purposes, I was just trying to pull the value and display it in a message box. When I run this, I just get a blank message box.

Code: Select all

sub FigureDialog

BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Test1")
otxt1 = oDialog1.GetControl("txt_SrcCol")
MsgBox otxt1.Text

end sub

I must be missing something very simple here, but I can't seem to find any explanation via google of what I'm doing here.

Any insight would be appreciated.
Last edited by cdub on Sat Mar 22, 2008 12:30 am, edited 1 time in total.
ms777
Volunteer
Posts: 177
Joined: Mon Oct 08, 2007 1:33 am

Re: Get Text value from text box on dialog

Post by ms777 »

Hi,

try

Code: Select all

sub FigureDialog

BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Test1")
oDialog1.execute
otxt1 = oDialog1.GetControl("txt_SrcCol")
MsgBox otxt1.Text

end sub
cdub
Posts: 7
Joined: Tue Mar 18, 2008 4:41 am

Re: Get Text value from text box on dialog

Post by cdub »

Thank you for the tip. Adding that line made another instance of my dialog appear. If I put text in the box, then close the box, I get a msgbox with my text in it.

I'm starting to think this is a variable scope issue.

I have a button on my spreadsheet that when clicked opens this dialog (On click - runs Sub AvgDialog_Show).
Then, I push a "RUN" button in the dialog which should get the users inputted value and display in the msgbox (Sub FigureDialog).

Here's my setup (I'm showing the second oDialog1.Execute() remarked out, but I've been playing with turning it off and on....) :

Code: Select all

Sub AvgDialog_Show
 DialogLibraries.LoadLibrary( "Standard" )
 oDialog1 = CreateUnoDialog( DialogLibraries.Standard.Test1 )
 oDialog1.Execute()
End Sub

sub FigureDialog
	BasicLibraries.LoadLibrary("Tools")
	oDialog1 = LoadDialog("Standard", "Test1")
	'oDialog1.Execute()
	otxt1 = oDialog1.GetControl("txt_SrcCol")
	MsgBox otxt1.Text()
end sub
The only other curve ball I've got going on with this program is that I'm using the .xls format to store the file. I'm having to do this because the secondary program I'm feeding the data into only imports .xls file format......
cdub
Posts: 7
Joined: Tue Mar 18, 2008 4:41 am

Re: Get Text value from text box on dialog

Post by cdub »

Ok, "Learn OpenOffice.org Spreadsheet Macro Programming" by Dr. Bain showed up today from Amazon.

Indeed I was having a variable scope issue.

All I needed to do was declare the dialog outside of the sub routine. Then I didn't need some of the other stuff in the subs.

a button in my spreadsheet calls AvgDialog_Show
Clicking a "run" button in the dialog calls FigureDialog

Code: Select all

REM declare dialog object "globally"
dim oDialog1 as object

Sub AvgDialog_Show
	BasicLibraries.LoadLibrary("Tools")
	oDialog1 = LoadDialog("Standard", "Test1")
	oDialog1.Execute()
End Sub

sub FigureDialog
	Dim otxt1 as Object
	otxt1 = oDialog1.GetControl("txt_SrcCol")
	MsgBox otxt1.Text()
end sub

will edit this subject header to be solved....
Post Reply