[Solved] Progress Bar in macro

Discuss the database features

[Solved] Progress Bar in macro

Postby joaofmateus » Fri Feb 10, 2017 2:57 pm

I tried to build a progress bar to tell the user that I was doing a task, using a code I found here in the forum, but I could not get it to work. Here is the code:

Code: Select all   Expand viewCollapse view
Sub Contabiliza ()
Dim DatabaseContext As Object
Dim DataSource As Object
Dim Connection As Object
Dim Statement As Object
Dim ResultSet As Object
Dim oBarraEstado As Object
Dim co1 As Integer


'Inicia o processo de contabilização

Msgbox "A iniciar o processo de Contabilização"

'Referencia a barra de estado no documento activo
oBarraEstado = ThisComponent.getCurrentController.StatusIndicator
'Estabelece o texto inicial  e o limite da barra de progresso
oBarraEstado.start( "Processo de Contabilização a decorrer. Aguarde...", 3 )

'Limpa todos os movimentos contabilisticos
'Primeiro processo
     
'Esta Conexão só funciona em Bases de Dados Registadas
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName("contabilidade1")
Connection = DataSource.GetConnection("","")
'Connection=thisdatabasedocument.CurrentController.activeconnection

Statement = Connection.createStatement()
ResultSet = Statement.executeQuery("DELETE FROM ""tMOVIMENTOS_CONTA"";")
'Estabelece o valor da barra de progresso
oBarraEstado.setValue( 1 )

'Contabiliza os movimentos a Débito

'Segundo processo

'Esta Conexão só funciona em Bases de Dados Registadas
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName("contabilidade1")
Connection = DataSource.GetConnection("","")
'Connection=thisdatabasedocument.CurrentController.activeconnection
Statement = Connection.createStatement()
ResultSet = Statement.executeQuery("INSERT INTO ""tMOVIMENTOS_CONTA""(""ID_MOV"",""COD_CONTA"",""DATA_MOV"",""DESC_MOV"",""DEBITO"",""CREDITO"")SELECT ""ID_MOV"",""CONTA_DEB"" AS ""COD_CONTA"",""DATA_MOV"",""DESC_MOV"",""VALOR"" as ""DEBITO"",0 AS ""CREDITO"" FROM ""tMOVIMENTOS"";")
'Estabelece o valor da barra de progresso
oBarraEstado.setValue( 2 )
'Contabiliza os movimentos a Crédito
'Terceiro processo
     

'Esta Conexão só funciona em Bases de Dados Registadas
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName("contabilidade1")
Connection = DataSource.GetConnection("","")
'Connection=thisdatabasedocument.CurrentController.activeconnection
Statement = Connection.createStatement()
ResultSet = Statement.executeQuery("INSERT INTO ""tMOVIMENTOS_CONTA""(""ID_MOV"",""COD_CONTA"",""DATA_MOV"",""DESC_MOV"",""DEBITO"",""CREDITO"")SELECT ""ID_MOV"",""CONTA_CRED"" AS ""COD_CONTA"",""DATA_MOV"",""DESC_MOV"",0 as ""DEBITO"",""VALOR"" AS ""CREDITO"" FROM ""tMOVIMENTOS"";")
'Estabelece o valor da barra de progresso
      oBarraEstado.setValue( 3 )
'Finaliza a barra de progresso para devolver o controlo ao utilizador
   oBarraEstado.end()
Msgbox "Processo de Contabilização concluído"

End Sub


Could anyone help me figure out where I'm failing?
Last edited by RoryOF on Fri Feb 10, 2017 6:21 pm, edited 2 times in total.
Reason: Added green tick [RoryOF, Moderator]
OOo 4.1.5 on MS Windows 10
joaofmateus
 
Posts: 33
Joined: Fri Mar 20, 2009 12:15 pm
Location: Lisbon - Portugal

Re: Progress Bar in macro

Postby Zizi64 » Fri Feb 10, 2017 3:52 pm

https://wiki.openoffice.org/wiki/Docume ... ogress_Bar

You must create a Dialog with a Progressbar manually for working the linked example code. The code can show/hide and modify it, but will not create it.
Tibor Kovacs, Hungary; LO6.1.6 on Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.3.3; AOO4.1.6
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 8534
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Progress Bar in macro

Postby joaofmateus » Fri Feb 10, 2017 5:50 pm

Thank you Zizzi64.
I have adapted the code as follows and it works:
Code: Select all   Expand viewCollapse view
Sub Contabiliza()
Dim DatabaseContext As Object
Dim DataSource As Object
Dim Connection As Object
Dim Statement As Object
Dim ResultSet As Object
Dim oBarraEstado As Object
Dim co1 As Integer


'Inicia o processo de contabilização

'Msgbox "A iniciar o processo de Contabilização"


   'Referencia a barra de estado do documento activo
   oBarraEstado = ThisComponent.getCurrentController.StatusIndicator
   'Estabelece o texto inicial e  o limite da barra de progresso
   oBarraEstado.start( "Processo de Contabilização ", 10 )
   For co1 = 1 To 10
      'Estabelece o valor da barra de progresso
      oBarraEstado.setValue( co1 )
      'Y el texto, and the text
      oBarraEstado.setText( "Processo de Contabilização a Decorrer. Aguarde : " & co1 )
      'Espera um segundo
      Wait 1000
   Next

'Limpa todos os movimentos contabilisticos

'Esta Conexão só funciona em Bases de Dados Registadas
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName("contabilidade1")
Connection = DataSource.GetConnection("","")
'Connection=thisdatabasedocument.CurrentController.activeconnection

Statement = Connection.createStatement()
ResultSet = Statement.executeQuery("DELETE FROM ""tMOVIMENTOS_CONTA"";")


'Contabiliza os movimentos a Débito

'Esta Conexão só funciona em Bases de Dados Registadas
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName("contabilidade1")
Connection = DataSource.GetConnection("","")
'Connection=thisdatabasedocument.CurrentController.activeconnection
Statement = Connection.createStatement()
ResultSet = Statement.executeQuery("INSERT INTO ""tMOVIMENTOS_CONTA""(""ID_MOV"",""COD_CONTA"",""DATA_MOV"",""DESC_MOV"",""DEBITO"",""CREDITO"")SELECT ""ID_MOV"",""CONTA_DEB"" AS ""COD_CONTA"",""DATA_MOV"",""DESC_MOV"",""VALOR"" as ""DEBITO"",0 AS ""CREDITO"" FROM ""tMOVIMENTOS"";")

'Contabiliza os movimentos a Crédito

'Esta Conexão só funciona em Bases de Dados Registadas
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName("contabilidade1")
Connection = DataSource.GetConnection("","")
'Connection=thisdatabasedocument.CurrentController.activeconnection
Statement = Connection.createStatement()
ResultSet = Statement.executeQuery("INSERT INTO ""tMOVIMENTOS_CONTA""(""ID_MOV"",""COD_CONTA"",""DATA_MOV"",""DESC_MOV"",""DEBITO"",""CREDITO"")SELECT ""ID_MOV"",""CONTA_CRED"" AS ""COD_CONTA"",""DATA_MOV"",""DESC_MOV"",0 as ""DEBITO"",""VALOR"" AS ""CREDITO"" FROM ""tMOVIMENTOS"";")

'Finaliza a barra de progresso para devolver o controlo ao utilizador
   oBarraEstado.end()
Msgbox "Processo de Contabilização concluído"

End Sub
OOo 4.1.5 on MS Windows 10
joaofmateus
 
Posts: 33
Joined: Fri Mar 20, 2009 12:15 pm
Location: Lisbon - Portugal


Return to Base

Who is online

Users browsing this forum: No registered users and 4 guests