Shared variable example

Events in FORMS are not aware of each other. In order to share data between events, shared variables are needed. This example demonstrates how the GetSharedVariable and SetSharedVariable methods work. For each interpreted form, the number of interpreted fields are counted.

 

Function OnFormInterpret ( ) As Long

    'Reset the "FieldCount" variable to 0

    InterpretApp.SetSharedVariable ("FieldCount", "0")

 

    OnFormInterpret = EV_OK ' Return value to FORMS

 

End Function

 

Function OnFieldInterpreted() As Long

'---------------------------------------------------------------------

' This event is fired after the field is interpreted.

' This function counts the number of interpreted fields.

'

' The Get/SetSharedVariable uses a string to store the value.

' The stored value must be converted to the right format using Val()

' or Str().

'---------------------------------------------------------------------

    Dim Counter As Integer

    'Get the shared "FieldCount" variable, if there is one.

    Counter = Val(InterpretApp.GetSharedVariable("FieldCount"))

 

    'Increase counter

    Counter = Counter + 1

 

    'Store the new counter value in "FieldCount"

    InterpretApp.SetSharedVariable ("FieldCount", Str(Counter))

 

    OnFieldInterpreted = EV_OK ' Return value to FORMS

End Function

 

Function OnFormInterpreted() As Long

'---------------------------------------------------------------------

' This event is fired after the entire form is interpreted.

' This function displays how many fields were interpreted on form.

'---------------------------------------------------------------------

    Dim Counter As String

    Dim strMsg As String

    ' Get the shared variable "FieldCount"

    Counter = InterpretApp.GetSharedVariable("FieldCount")

 

    ' Display how many interpreted fields there were

    strMsg = "The number of interpreted fields on this form was: "

    MsgBox strMsg & Counter

 

    OnFormInterpreted = EV_OK ' Return value to FORMS

End Function