Basic VBScript for Elipse E3: Lesson 4 – Events

Screen Events

KeyDown (KeyCode, Shift)

This occurs at the moment a button is pressed, regardless of the focus on the screen.
KeyCode: Integer that identifies the ASCII character of the pressed button.
Shift: Displays the pressed button alongside the mouse click: 4 = Key [Shift]; 8 = Key [Ctrl]; 12 = Keys [Ctrl] + [Shift].

Example:

Sub Screen1_KeyDown(KeyCode, Shift) 
'Displays a message box when the user presses a button
MsgBox "Button code: " & KeyCode
End Sub

Exercises:

1. When the user presses Esc on screen, quit the Viewer.
2. When the combination Ctrl+Y is pressed, display a message box.

MouseDown (Button, ShiftState, MouseX, MouseY)

This occurs when any mouse button is pressed on the screen. Use MouseDown event to determine specific actions when the screen is clicked by users.
Button:  1 -The pressed mouse button is the left one. 2 – The pressed mouse button is the right one.
ShiftState: Displays the pressed key with the mouse: 4 = Key [Shift]; 8 = Key [Ctrl]; 12 = Keys [Ctrl] + [Shift].
MouseX:Displays the X position where the mouse was clicked on screen.
MouseY: Displays the Y position where the mouse was clicked on screen.

Example:

MsgBox “Coordinate X: ” & MouseX & vbNewLine & “Coordinate Y: ” & MouseY

Exercises:

3. By clicking with the left button on screen, display a calendar on the click’s x and y coordinates.
4. By right-clicking on screen, open the color pallet (ShowColorPicker) and change screen background’s color.

OnPreShow (Arg)

This occurs before the screen is displayed. The Arg variable receives the content from the OpenScreen() method’s Arg parameter, which generates this event.

Example:

In a button on the home screen, we inserted the script below, where the word “scrap” is the Arg parameter.


Sub CommandButton1_Click()
Application.GetFrame("").OpenScreen("Screen1"), "Scrap"
End Sub
In the OnPreShow event from Screen1, we display Arg on a message box:
Sub Screen1_OnPreShow(Arg)
    MsgBox Arg   
End Sub

Exercises:

5. On a screen, create a setpoint and a button to call a second screen. Pass what was typed in the setpoint through Arg parameter.
6. The second screen must show the Arg parameter on a display.
7. Create an Xcontrol with an Engine design, named XEngine.
8. Input 3 XEngines on the screen.
9. By clicking on XEngine, a screen must open (always the same screen) and a display of this second screen must show the clicked XEngine’s name.

Setpoint Events

Validate (Cancel, NewValue)

This occurs after the testing of the SetPoint’s limits and before SetPoint’s value is sent to the tag. This event’s purpose is to enable the user to cancel the sending of the SetPoint’s value to the tag. The old value can be accessed through the SetPoint’s Value Property.
Cancel: Boolean that indicates if the operation of assigning SetPoint’s value to the tag must be canceled.  (Cancel = True). Default is False
NewValue:  the value that is being rated.

Example:

Sub Setpoint1_Validate(Cancel, NewValue)
' Displays a MsgBox that asks the user if they want to use the new value typed in the SetPoint
message = "Current Value: " & Value & vbnewline & "New Value: " & NewValue & vbnewline & "Accept new value?"
If MsgBox(message, vbQuestion+vbYesNo, "Validate Event")=vbNo Then
    Cancel = True
End If
End Sub
Exercises:

10. Insert a setpoint and a display on screen. Link both to the same internal tag.
11. If the value typed in the SetPoint is different from 10, 20 or 30, a message must be displayed to the user telling them that the value is not allowed. The value must not be passed to the tag.

E3Browser Events

OnDrawRow (Selected, Line, RowTextColor, RowBackColor)

Selected:  indicates if the row is selected;
Line: indicates the number of the row being drawn;
RowTextColor:  indicates row’s text color;
RowBackColor: indicates text’s background color.
If the color is changed in this event, this change will be used by E3Browser in the row design. If GetColumnValue() method is called  from inside the event, the values returned will be from the row being designed, and not from the selected row.

Example:

Status = GetColumnValue(1)
If Status=0 then
    RowTextColor = RGB(255,0,0) ‘red
Else
RowTextColor = RGB(255,0,0) ‘green
End if

Exercises:

12. Insert a Database object in the application and configure it.
13. Create a demonstration tag.
14. Insert an alarm to the demonstration tag.
15. Save the alarms in the Database.
16. Display the alarm data in the E3Browser.
17. If the record is an alarm entry, its color must be red. If it is alarm acknowledgement, its color must be blue. If it is an alarm return, its color must be black.


E3Chart Events

OnLegendClick(Row, Col, RowData)

This occurs when the user clicks on a legend row. Row and Col parameters indicate, respectively, the row and the column that were clicked. RowData parameter is the index of the legend’s pen where the click occurred.

Example:

Sub E3Chart1_OnLegendClick(Row, col, RowData)
MsgBox “Name of the pen: ” & Pens.Item(RowData).name
End Sub

Exercises:

18. Create a chart on screen with at least 3 pens. Display the legend.
19. In OnStartRunning event from E3Chart, enter the code below so that all the pens always appear:
Sub E3Chart1_OnStartRunning()
    Legend.ShowAllPens = True   
End Sub
20. By clicking on a pen in the legend, display a menu with the options Visible and Color (Select Menu).
21. By clicking on the Visible option, the pen must appear/disappear.
22. By clicking on the Color option, a color palette must open, where it is possible to choose the pen’s new color.

Attachments:

Lesson4.zip

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *