Basic VBScript for Elipse E3: Lesson 2 – Reference to Objects

Application

The word Application represents the application as a whole, and indicates functions that are either executed in the E3 Viewer or executed in the server. The object Application knows in advance which functions must be executed in either case. It is not possible, however, to execute functions from the E3 Viewer in the server, or functions from the server in the E3 Viewer.

Example:

Application.ChangePassword(): Viewer’s function that allows to change current user’s password.
Application.Trace (message): Server’s function that writes in a text file.

Exercises:

Viewer
1. Create at least 2 users, being one of them an Administrator.
2. Create a button to login (Login method)
3. Create a button to change user’s password (ChangePassword method).
4. Create a button to call the user administration. (UserAdministration method)
5. Create a button to confirm password(PasswordConfirm method)
6. Create a button to display the user’s full name(GetFullUserName method)

Server
7. Create an Internal tag.
8. In Internal Tag’s OnStartRunning event, use Trace method to create a text file with the message “Tag started”.

Server Objects

To access an object that is being executed in the server through a Screen Object or an ElipseX, use the GetObject method from the Application Object.

Example:


Figure 6

Application.GetObject(“Data.InternalTag1”): InternalTag from the Data Server.
Application.GetObject(“Database”): Database

Exercises:

9. Insert a demo tag and an internal tag in the application.
10. Display on a MessageBox the name of the internal tag created in the previous exercise.
11. Display on a MessageBox the name of the demo tag created in the previous exercise.

Item

The Item method returns a reference to the child object from the object that called it. This method can search an object by name or by index (integer). If the index or the specified name is valid, the Item() method returns the reference to the object. Otherwise, the method returns an “invalid parameter” error.

Example:


Figure 7

Screen.Item(“E3Browser1”): E3Browser1 object that is on screen.
Screen.Item(“E3Browser1”).Item(“Query1”):Query1 Object that is in E3Browser.

Exercises:

12. Create two texts on the screen with any message you wish.
13. Group texts.
14. Display on a MessageBox the name of the group created in the previous exercise.
15. Display on a MessageBox the name of the text created in the previous exercise.
16. Which of the alternatives is the correct way to refer to Query1 object?


Figure 8

Set Command

The VBScript implements the concept of object-oriented languages, allowing that a variable of Variant type takes form of any object, through the Set command. Thus, the variable serves as a pointer to the desired object, allowing accessing its methods and properties.

Example:

Set rectangle = Screen.Item(“Rectangle1”)
rectangle.BackgroudColor = RGB (255,0,0)

Without the Set command, the same call would have to be:

Screen.Item(“Rectangle1”).BackgroudColor = RGB(255,0,0)

Apparently, there is no advantage in this case, because it all can be done in just one code line. However, if other operations are necessary just below the same script, the process becomes simpler and faster if the call from Item() method has not been placed on all lines.

Bad example:

Screen.Item(“Rectangle1”).BackgroudColor = RGB(212,208,20)
Screen.Item(“Rectangle1”).Height = 500
Screen.Item(“Rectangle1”).Width = 500

Better example:

Set Rectangle = Screen.Item(“Rectangle1”)
Rectangle.BackgroudColor = RGB(212,208,20)
Rectangle.Height = 500
Rectangle.Width = 500

Exercises:

17. Insert a chart onto screen with a pen. Set it to display legends.
18. By clicking on the chart’s legend, display on a message box both pen’s color and name. Use Set command.
19. By clicking on the chart, show both pen’s X and Y positions on two displays on screen.

Attachments:

Lesson2.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 *