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

Fill listbox from another subroutine ??

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


Joined: 14 Jul 2003
Posts: 13
Location: Duisburg, Germany

PostPosted: Thu Aug 07, 2003 2:08 am    Post subject: Fill listbox from another subroutine ?? Reply with quote

Hello,
i want to fill a listbox with data from database.
That is in another subroutine as i call the frame.
If i want to call the subroutine Fill_ListBox with a button,
the listbox in the frame does not fill.

Sub Fill_ListBox
REM *** Connection to the Database opens before ***
Statement = Connection.createStatement()
ResultSet = Statement.executeQuery("select FIRST " & "30" &_
" fb_id from sicadi.a_druckanschrift where druckstatus = 1")

If Not IsNull(ResultSet) Then
While (ResultSet.next)
For i = 1 To 1
sMySQLString = ResultSet.getString(i)
oListBox = oDialog.getControl("FB_Liste1")
oListBox.addItem( sMySQLString, 1 )
Next i
Wend
End If
End Sub

If i use this code in the sub call-frame, the listbox is filled.
I hope, I articulated my problem understandably.
Thanks a lot.

Greetings
Carsten Klein
Back to top
View user's profile Send private message
openmind
OOo Enthusiast
OOo Enthusiast


Joined: 28 Jun 2003
Posts: 106
Location: Switzerland

PostPosted: Fri Aug 08, 2003 2:51 am    Post subject: Reply with quote

Following code works on OOO1.1rc. In my opinion it should work on OOo1.x but i'm not sure. Try it out.

Code:
Sub FillListbox

   Dim writerDokument as Object
   Dim docController as Object
   Dim drawPage as Object
   Dim listBox as Object
   Dim listBoxView as Object
   
   writerDokument = thisComponent
   docController = writerDokument.CurrentController
   drawPage = writerDokument.DrawPage
   
   listBox = DrawPage.Forms.GetByName( "Standard" ).getByName( "listbox" )
   listBoxView = docController.getControl( listBox )
   listBoxView.addItem( "item" ,listBoxView.getItemCount() )

End Sub
Back to top
View user's profile Send private message
washington
General User
General User


Joined: 14 Jul 2003
Posts: 13
Location: Duisburg, Germany

PostPosted: Sun Aug 10, 2003 10:42 pm    Post subject: Fill listbox from another subroutine ?? Reply with quote

Hello,
when i try it out, i get the following exception at this point:
listBox = DrawPage.Forms.GetByName( "Standard" ).getByName( "listbox" )

Type: com.sun.star.container.NoSuchElementException

Greetings
Carsten
Back to top
View user's profile Send private message
openmind
OOo Enthusiast
OOo Enthusiast


Joined: 28 Jun 2003
Posts: 106
Location: Switzerland

PostPosted: Mon Aug 11, 2003 12:31 am    Post subject: Re: Fill listbox from another subroutine ?? Reply with quote

washington wrote:
Hello,
when i try it out, i get the following exception at this point:
listBox = DrawPage.Forms.GetByName( "Standard" ).getByName( "listbox" )

Type: com.sun.star.container.NoSuchElementException


Sure. The Listbox is called ByName("listbox"). You have to adjust the name of the listbox in the code or in the properties dialog of the listbox. Doesn't matter which one you adjust but In the end they must be the same.


Code:
listBox = DrawPage.Forms._
   GetByName( "Standard" ).getByName( "myNameIsWashington" )
Back to top
View user's profile Send private message
washington
General User
General User


Joined: 14 Jul 2003
Posts: 13
Location: Duisburg, Germany

PostPosted: Mon Aug 11, 2003 1:56 am    Post subject: Fill listbox from another subroutine ?? Reply with quote

Surely IŽd changed in:

listBox = DrawPage.Forms._
GetByName( "Standard" ).getByName( "FB_List1" )

As I defined before the lisbox.
Back to top
View user's profile Send private message
openmind
OOo Enthusiast
OOo Enthusiast


Joined: 28 Jun 2003
Posts: 106
Location: Switzerland

PostPosted: Mon Aug 11, 2003 5:42 am    Post subject: Reply with quote

Sorry for not mention it: it should work if you adjusted the name of the form a n d the name of the control.

Did you made a new form or did you insert your controls in the 'standard'-Form which already existed?

To see which element is missing you can split the code in two lines:

Code:
Dim form as Object
form = DrawPage.Forms.GetByName( "Standard" )
listBox = form.getByName( "listbox" )


When the error occured it shows you at which line the error is (form or listbox?). In the former example you can't distingush between missing the form or missing the conrtol with the information of error line.[/code]
Back to top
View user's profile Send private message
washington
General User
General User


Joined: 14 Jul 2003
Posts: 13
Location: Duisburg, Germany

PostPosted: Mon Aug 11, 2003 10:41 pm    Post subject: Fill listbox from another subroutine ?? Reply with quote

Hello,
I use the 'standard' - Form and the error is in the following line:
Code:
form = DrawPage.Forms.GetByName( "Standard" )

The module that's start at the begin of the program, opens as follows:
Code:
REM *** fForDruck is the module which is called ***
oDialog = createUnoDialog(DialogLibraries.Standard.fForDruck)
Back to top
View user's profile Send private message
openmind
OOo Enthusiast
OOo Enthusiast


Joined: 28 Jun 2003
Posts: 106
Location: Switzerland

PostPosted: Tue Aug 12, 2003 12:54 am    Post subject: Reply with quote

Now i see. We are talking from diffferent things. I'm talking about forms and your talking about dialogs; thats a difference Wink
I pointed you in the wrong direction. Sorry about that.

Code:
Global oDialog as Object

Sub openDialog
   oDialog = createUnoDialog(DialogLibraries.Standard.fForDruck)
   oDialog.execute()
End Sub

Sub anotherRoutine
   oDialog.getControl( "FB_List1" )
   ' do what you want with your listbox
End Sub

Sub thirdSubroutine
   oDialog.endExecute()
End Sub


Deklar the dialog as a global variable to access it from any other subroutine you want.

I should read the posting more precise Wink
Back to top
View user's profile Send private message
washington
General User
General User


Joined: 14 Jul 2003
Posts: 13
Location: Duisburg, Germany

PostPosted: Tue Aug 12, 2003 1:19 am    Post subject: Fill listbox from another subroutine ?? Reply with quote

Sorry, if I expressed misleadingly. Wink
That, what you had written had I already tried out, but the current dialog simply not filled.
My Code:
Code:
sMySQLString = ResultSet.getString(i)
oListBox = oDialog.getControl("FB_List1")
oListBox.addItem( sMySQLString, 0 )
Back to top
View user's profile Send private message
washington
General User
General User


Joined: 14 Jul 2003
Posts: 13
Location: Duisburg, Germany

PostPosted: Tue Aug 12, 2003 2:02 am    Post subject: Fill listbox from another subroutine ?? Reply with quote

Oh my god, I forgot to initialize the oDialog - variable as GLOBAL.
I'm so blind. Cool
Thankyou very much, for your generous assistance.

Greetings
Carsten
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