Previous Topic

Next Topic

Book Contents

Book Index

FD Tutorial: Custom Form refreshed on a timer

This tutorial will show you how to create a form that displays an amount that is regularly refreshed on a timer.

  1. Go to Navigator > Setup > Form Designer. Form Designer will open with a blank form.
  2. Add a Label component. You can do this by selecting Label from the Component menu, then clicking the form, or by clicking the UserLabel Label component icon, then clicking the form.
  3. Set the Caption for the label to Sales Invoices Value this Period To Date. Resize the label to fit the caption.
  4. Add another label under the first label. This one will display the calculated Sales Invoices Value for the current period.
  5. Click in the Font properties to change the Font Size for the label. Enter a larger font size, such as 14. Set the Label name to lSalesValue.
  6. Add a UserTimer Timer component. This component is not shown on the form, so it doesn't matter where you place it.
  7. Go to the Code tab. Enter code to add the Gross Amount Bs for Invoices in the current period. Enter the following code:

    Sub CalcSalesValue
      Dim SalesValue as Number
      SalesValue = 0
      Dim INHead as Object
      INHead = OpenTable("INHead")
      InHead.IndexName = "PeriodDocument"
      INHead.SetRange(CurrentPeriod("IN"))
      Do
        If INHead.DocumentClass = "I" Then SalesValue = SalesValue + INHead.GrossAmountBs
        INHead.Next
      Loop Until INHead.EOF
      lSalesValue.Caption = FormatNumber(SalesValue,",0.00")
    End Sub

    Note: This code adds values for Posted and Unposted Invoices, and excludes Credits. You can modify the code if you want to change this.

  8. Go to the Layout tab. Select the form from the component list. Go to the Events tab. Set the OnShow event to CalcSalesValue.
  9. Select the Timer component. Set the Enabled property to True. Set the Interval to 600000. This is the millisecond equivalent of 10 minutes.
  10. Go to the Events tab. Set the OnExecute event to CalcSalesValue.
  11. Click Run (Ctrl+R). The form will display the Sales Invoice Value for this period, and will update the figure every ten minutes.
  12. You can Save the form, then add it to a shortcut on the Menu Bar or in the Navigator. See Script Shortcut Editor.
  13. To change the form from a Normal Window to a Floating Window, click the Accredo Mercury or Saturn icon in the top left corner of the form, then select Move to New Window. To change it back to a Normal Window, click the icon again and select Move to Main Window.