C1Awk Reference > C1Awk Events > Variable Event |
Fired when the Val property is used to evaluate a formula that contains variables.
Private Sub C1Awk_Variable(Variable As String, Value As Double, Accept As Integer)
This event is used with the Val property to provide evaluation of expressions that contain variables.
The parameters for the Variable event are described below:
Variable$
This parameter holds the name of the variable that needs to be evaluated.
Value#
This parameter is where the event handler must return the value of the variable.
Accept%
This parameter indicates that the variable is valid. It is False by default. If the variable name is valid, then the handler is responsible for setting this parameter to True.
Your event handler will typically read the variable name from the Variable parameter, supply its value through the Value parameter, and set the Accept flag to indicate the variable is valid. If the variable name is not valid, it will return without setting the Accept parameter and Awk will generate a "Bad Token" error.
For example, if your program defines two variables "x" and "y", your event handler might look like this:
Example Title |
Copy Code
|
---|---|
Dim GlobalX, GlobalY Sub awk_Variable(Variable$, Value As Double, Accept%) Accept = True Select Case Variable Case "X", "x": Value = GlobalX Case "Y", "y": Value = GlobalY Case Else: Accept = False ' trigger error End Select End Sub GlobalX = 1 GlobalY = 2 awk = "X + Y" Debug.Print awk.Val 3 |