Ask Your Question
0

Create a time-delay messagebox in Base

asked 2016-12-11 05:29:38 +0200

LeftyMaus gravatar image

I am running Libre Office 5.2.3.3. I have a form that I created in Base that posts a timestamp to a table; similar to a punch-clock.

After the user punches in or out, there is a MsgBoxconfirmation message which the user then has to dismiss. I would like to replace the confirmation message with one that will self-dismiss after a few seconds.

I thought I could accomplish this by creating a label field and control it's visibility by adding a few more lines to the timestamp macro. I've spent loads of time googling and trying and testing. But I can't seem to figure out the syntax. In particular, I believe I'm failing to properly address the label field. Below are several examples of code that do similar things.

example 1

adapted from: http://www.access2base.com/access2bas...

sub GetControlVal

    Dim ocControl As Object
    ocControl = ofForm.Controls("confirm1")
    MsgBox ocControl.Value
    'ocControl.Visible = False

end sub

example 2

adapted from: https://forum.openoffice.org/en/forum...

sub HideButton3
    dim button3 as object
    Button3 = StarDesktop.CurrentComponent.DrawPage.Forms.GetByIndex(0).getByName("Push Button 3")
    thiscomponent.currentcontroller.getcontrol(Button3).setVisible(False)

end sub

example 3

adapted from: https://forum.openoffice.org/en/forum...

sub threeseconds
    Doc = ThisComponent
    Sheet = Doc.Sheets.getByIndex(0)
    Page = Sheet.DrawPage
    Form = Page.Forms.getByIndex(0)

    'txtlabel is an object of type com.sun.star.comp.forms.OButtonModel
    txtlabel = Form.getByName("confirm1")

    'txtlabelCtrl is an object of type com.sun.star.comp.forms.OButtonControl  
    txtlabelCtrl = Doc.CurrentController.getControl(txtlabel)

    'This can control object size, position, visibility, etc.
    txtlabelCtrl.setVisible(False)
    Wait 3000
    txtlabelCtrl.setVisible(True)

end sub

example 4

adapted from: https://ask.libreoffice.org/en/questi...

Function ToggleShowHide(ShowHideVariable As Boolean )
    RootForm = ThisComponent.Drawpage.Forms
    MainForm = RootForm.getByName("MainForm")

    i = 0

    Do While i < MainForm.Count

    If Right(MainForm.getByIndex(i).ServiceName, 4) <> "Form" And _
    Right(MainForm.getByIndex(i).Name, 6) <> "NoHide" Then
        MainForm.getByIndex(i).EnableVisible = ShowHideVariable
    End If
    i = i + 1

    Loop
End Function

I get the general idea, but it is not clear to me which method is the one I should be using, to implement this improved messagebox feature into Base with a macro.

edit retag flag offensive close merge delete

Comments

Note that none of the four examples actually work on my database. I show them here to illustrate the many methods I have found.

LeftyMaus gravatar imageLeftyMaus ( 2016-12-11 23:54:05 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2016-12-11 06:03:45 +0200

Ratslinger gravatar image

updated 2016-12-12 02:26:13 +0200

Example 3 is the simplest to incorporate. setVisible(TRUE) to display and (FALSE) to hide. You can use a label control and set the displayed time with the Wait command.

The only drawback to having hidden elements it in editing the form. Sometimes it's in the way and has to be temporarily moved out of the way. All these are basically the same principle.

Example 1 uses Access2Base - more code necessary. Example 3 uses a button - user interface. Example 4 loops through controls to hide/reveal.

Edit: 12/11/2016

To make things easier, the code necessary is included in a working sample. Just run Form1, click the button and the push button will hide and the message will display for three seconds. After three seconds the message box will hide and the button appear. There are comments in the code explaining.

Sample: TimedLabelDisplay.odb

edit flag offensive delete link more

Comments

Almost forgot. When editing the form to insert this control, in the controls' properties General tab, set Visible to No. this way the control is not visible until the code turns it on.

Another thought, a timed dialog.

Ratslinger gravatar imageRatslinger ( 2016-12-11 06:53:14 +0200 )edit

I'd like to try example 3, but it throws an error on the second line Sheet = Doc.Sheets.getByIndex(0). I'm assuming this is because I'm running a Base program, and not a Calc program. Any suggestions how I might adapt it for Base?

LeftyMaus gravatar imageLeftyMaus ( 2016-12-12 00:07:45 +0200 )edit

Your assumption is correct. If you are going to be dealing with macros, you should read up on it. A sample has been provided in my answer.

Ratslinger gravatar imageRatslinger ( 2016-12-12 02:28:11 +0200 )edit

Example is very helpful, and much appreciated.

LeftyMaus gravatar imageLeftyMaus ( 2016-12-12 03:00:51 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-12-11 05:29:38 +0200

Seen: 235 times

Last updated: Dec 12 '16