{"id":2013,"date":"2019-03-25T17:37:39","date_gmt":"2019-03-25T20:37:39","guid":{"rendered":"http:\/\/xexeu.elipse.com.br\/pt\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/"},"modified":"2022-03-29T10:18:57","modified_gmt":"2022-03-29T13:18:57","slug":"connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library","status":"publish","type":"post","link":"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/","title":{"rendered":"Connecting a VBA application to an E3 Server using the E3DataAccess library."},"content":{"rendered":"<div style=\"text-align: justify\">\n<div align=\"justify\">\n<p><b>GENERAL NOTES<\/b><\/p>\n<ol>\n<li>This article applies to <b>Elipse E3<\/b>, versions <b>4.0<\/b> or <b>lower<\/b>.<\/li>\n<li>There is a <a href=\"http:\/\/kb.elipse.com.br\/pt-br\/questions\/5192\" target=\"_blank\" rel=\"noopener noreferrer\">bug<\/a> when using E3DataAccess library in typeless languages, such as VBScript and JavaScript.<\/li>\n<li>This feature is only compatible with 32-bit applications.<\/li>\n<\/ol>\n<\/div>\n<p><span style=\"font-weight: bold\">1) Introduction<\/span><\/p>\n<p>The <span style=\"font-weight: bold\">E3DataAccess <\/span>Library enables a new way to connect to the E3 Server. Now, you can connect any application developed on VB, Delphi, .NET or other language that supports COM to the E3 Server by using this Library&#8217;s functions.<\/p>\n<p>This article explains how the E3 Server works with a VBA application developed on Microsoft Excel. You can also use the procedures shown in this article for other languages, just adjusting the source codes according to the used language&#8217;s syntax.<\/p>\n<p><span style=\"font-weight: bold\">2) Enabling the E3DataAccess Library&#8217;s usage on VBA <\/span><\/p>\n<p>Before creating the application via VBA, you must enable the E3DataAccess Library&#8217;s usage on the development environment. After that, all necessary functions to communicate to the E3 Server become available.<\/p>\n<p>After properly installing E3 Studio, Microsoft Excel and VBA, you must access the Excel application&#8217;s VBA interface to add the E3DataAccess Library to the project&#8217;s references list. To do so, open the Tools &#8211; References menu, according to the next figure:<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura1.PNG\" alt=\"\" width=\"550\" height=\"449\" align=\"bottom\" border=\"0\" \/><\/div>\n<div style=\"text-align: center\"><span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 1<\/span>: Accessing the project&#8217;s references list<br \/>\n<\/span><\/div>\n<p>In the list of available references, select the <span style=\"font-weight: bold\">E3DataAccess <\/span>Library checkbox.<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura2.PNG\" alt=\"\" width=\"447\" height=\"354\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 2<\/span>: List of available references in the project<\/span><\/div>\n<p>If the Library is not available, you must register it first. To do so, click the Browse button to display a dialog box to select the library file (Figure 3).<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura3.PNG\" alt=\"\" width=\"473\" height=\"395\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 3<\/span>: Dialog box to select the library file<\/span><\/div>\n<p>Select the E3DataAccess.dll file. You can find it in the E3 installation directory&#8217;s Bin subfolder (for example: <span style=\"font-style: italic\">C:\/Program Files\/Elipse E3\/Bin<\/span>). After opening the DLL file, the <span style=\"font-weight: bold\">E3DataAccess <\/span>becomes available and you can enable it. Then, just click the OK button to confirm the change.<\/p>\n<p><span style=\"font-weight: bold\">3) Instancing a new E3DataAccess object in the project <\/span><br style=\"font-weight: bold\" \/>In this example, a new Module will be added to the project and an <span style=\"font-weight: bold\">E3DataAccess <\/span>object will be instanced in this module.<\/p>\n<p>To create a new Module, right-click the project in the Project Explorer tab (Figure 4), and select the Insert &#8211; Module option.<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura4.PNG\" alt=\"\" width=\"550\" height=\"449\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 4<\/span>: Inserting a new Module via VBA<\/span><\/div>\n<p>Then, edit the Module&#8217;s name to <span style=\"font-style: italic\">E3ServerCOM<\/span>.<\/p>\n<p>Now, you must double-click the <span style=\"font-style: italic\">E3ServerCOM <\/span>module to access its source code. Insert the following line to instance the E3DataAccess object:<\/p>\n<pre>Public E3 As New E3DATAACCESSLib.E3DataAccessManager<\/pre>\n<p>With this line, a new object named E3 is created derived from the E3DATAACCESSLib.E3WebLinkMan class. This class has all necessary functions to connect to the E3 Server. The object is also instanced as public, so it can be used anywhere in the project.<\/p>\n<p><span style=\"font-weight: bold\">NOTE:<\/span> *It is important to notice that when instancing an E3DataAcces object, you use one Viewer license. You can check this by accessing the E3 Server&#8217;s menu Licenses option. So, you must be careful to not use more licenses than the necessary.<\/p>\n<p>*From version 4.5.208 on, E3Server has featured unlimited support to E3DataAccess and E3AccessLayer connections, thus consuming no Viewer licenses or any other type of licenses.<\/p>\n<p><span style=\"font-weight: bold\">4) E3 application <\/span><\/p>\n<p>To demonstrate the E3DataAccess&#8217;s reading and writing methods, you must create two Demo Tags and one Internal Tag in the E3 application&#8217;s Data Server. Besides, you must create a Historic with two fields, <span style=\"font-style: italic\">E3TimeStamp <\/span>and <span style=\"font-style: italic\">TagHist <\/span>(which stores the <span style=\"font-style: italic\">DemoTag2<\/span>&#8216;s values):<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura5.PNG\" alt=\"\" width=\"550\" height=\"362\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 5<\/span>: E3 application&#8217;s Historic<\/span><\/div>\n<p>You must also create an Access Database object named <span style=\"font-style: italic\">DataBase1 <\/span>to save all data in the <span style=\"font-style: italic\">Test.mdb<\/span> file. Then, link the <span style=\"font-style: italic\">Database1 <\/span>object&#8217;s DBServer property to the Historic.<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura6.PNG\" alt=\"\" width=\"550\" height=\"361\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 6<\/span>: E3 application&#8217;s Database<\/span><\/div>\n<p>After that, name the Historic&#8217;s table using its <span style=\"font-style: italic\">TableName <\/span>property and generate it by clicking the Create DB Structure button.<\/p>\n<p>Create a Query object in the Data Server and configure it to connect to the <span style=\"font-style: italic\">DataBase1 <\/span>and access the created Historic table. In the Query&#8217;s settings, create a query to return all data from the Historic table (Figure 7).<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura7.PNG\" alt=\"\" width=\"550\" height=\"411\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figura 7<\/span>: Query&#8217;s settings<\/span><\/div>\n<p><span style=\"font-weight: bold\">5) Reading and writing data with E3DataAccess<\/span><\/p>\n<p>After setting the E3 application, we get back to Excel. First, select its screen and create two Command Buttons, one to read a value from <span style=\"font-style: italic\">DemoTag1 <\/span>and one to write a value to <span style=\"font-style: italic\">InternalTag1<\/span>. To add the buttons, enable the Control Toolbox toolbars&#8217; visualization using the View &#8211; Toolbars &#8211; Control Toolbox menu, as you can see on the next figure:<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura8.PNG\" alt=\"\" width=\"550\" height=\"384\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 8<\/span>: Enabling the Control Toolbox bar in Excel<\/span><\/div>\n<p>In the Control Toolbox, select the <span style=\"font-style: italic\">CommandButton <\/span>item and add two buttons. Right-click the first button and access its properties to edit its Caption property to Read Value. Also edit the second button&#8217;s Caption property to <span style=\"font-style: italic\">Write <\/span>and buttons&#8217; Name property to <span style=\"font-style: italic\">readValueButton <\/span>and <span style=\"font-style: italic\">writeValueButton<\/span>, respectively.<\/p>\n<p>After that, insert the following lines in the <span style=\"font-style: italic\">readValueButton<\/span>&#8216;s source code. Double-click the button to open the VBA in the button&#8217;s Click() event:<\/p>\n<pre>Private Sub readValueButton_Click()\r\n   Dim timestamp As Variant\r\n   Dim quality As Integer\r\n   Dim value As Variant\r\n   \r\n   E3.Server = \"E3Server_HostName\"\r\n   \r\n   If E3.GetValue(\"Data.DemoTag1.Value\", timestamp, quality, value) Then\r\n      Range(\"D4\") = value\r\n      Range(\"E4\") = quality\r\n      Range(\"F4\") = timestamp\r\n   Else\r\n      MsgBox \"Connection failure!\"\r\n   End If\r\nEnd Sub<\/pre>\n<p>The E3 object in this code is the same public object instanced in the <span style=\"font-style: italic\">E3ServerCOM <\/span>module. It sets all operations and connections to the E3 Server, so it is the <span style=\"font-style: italic\">key <\/span>of the code. After setting the routine&#8217;s variables, a value is attributed to the E3 object&#8217;s Server property to set the E3 Server&#8217;s name to connect to. This must be configured before performing any operation in the Domain.<\/p>\n<p><span style=\"font-weight: bold\">Method GetValue(Link, TimeStamp, Quality, Value)<\/span><\/p>\n<p>To read the tag&#8217;s value, the GetValue() method is used and it receives the following input and output parameters:<\/p>\n<\/div>\n<ul style=\"text-align: justify\">\n<li>Link &#8211; input parameter that supplies the path of the object to be read.<\/li>\n<li>Timestamp &#8211; output parameter that receives the timestamp of the referenced Link.<\/li>\n<li>Quality &#8211; output parameter that receives the quality of the referenced Link.<\/li>\n<li>Value &#8211; output parameter that receives the value of the referenced Link.<\/li>\n<\/ul>\n<div style=\"text-align: justify\">\n<p>When it is called, the GetValue() method returns a Boolean value, <span style=\"font-weight: bold\">TRUE <\/span>if the operations is successfully performed or <span style=\"font-weight: bold\">FALSE <\/span>if it does not. In the previous code, we are reading data from <span style=\"font-style: italic\">DemoTag1 <\/span>and saving its value, quality and timestamp.<\/p>\n<p>If there is no problem when reading <span style=\"font-style: italic\">DemoTag1<\/span>, data is written in D4, E4, and F4 cells of Excel&#8217;s spreadsheet. So, when clicking the readValueButton, we have the following answer:<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura9.PNG\" alt=\"\" width=\"550\" height=\"384\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 9<\/span>: <span style=\"font-style: italic\">readValueButton<\/span>&#8216;s answer<\/span><\/div>\n<p>The next step is to write a value in <span style=\"font-style: italic\">InternalTag1<\/span>. To do so, insert the following lines in the <span style=\"font-style: italic\">writeValueButton<\/span>&#8216;s Click() event as you did to the first button (double-click it to open the code area):<\/p>\n<pre>Private Sub writeValueButton_Click()\r\n   Dim timestamp As Variant\r\n   Dim quality As Integer\r\n   Dim value As Variant\r\n   \r\n   value = CDbl(Range(\"D7\"))\r\n   quality = Range(\"E7\")\r\n   timestamp = DateTime.Now\r\n   \r\n   E3.Server = \"E3Server_HostName\"\r\n   \r\n   If E3.SetValue(\"Data.InternalTag1.Value\", timestamp, quality, value) Then\r\n      Range(\"G7\") = \"Success!\"\r\n   Else\r\n      Range(\"G7\") = \"Fail!\"\r\n   End If\r\nEnd Sub<\/pre>\n<p>In this code, we use D7, E7, and G7 cells to store <span style=\"font-style: italic\">value<\/span>, <span style=\"font-style: italic\">quality <\/span>and <span style=\"font-style: italic\">timestamp<\/span>, respectively, to write these values in <span style=\"font-style: italic\">InternalTag1<\/span>.<\/p>\n<p>After that, the connection is performed in E3 Server via E3 Object&#8217;s <span style=\"font-style: italic\">Server <\/span>property and the method is called.<\/p>\n<p><span style=\"font-weight: bold\">Method SetValue(Link, TimeStamp, Quality, Value)<\/span><\/p>\n<p>This method is syntactically identical to the GetValue method, it has the following input parameters:<\/p>\n<\/div>\n<ul style=\"text-align: justify\">\n<li>Link &#8211; input parameter that supplies the path of the object to be written.<\/li>\n<li>Timestamp &#8211; input parameter that supplies the timestamp of the referenced Link.<\/li>\n<li>Qualidade &#8211; input parameter that supplies the quality of the referenced Link.<\/li>\n<li>Valor &#8211; input parameter that supplies the value of the referenced Link.<\/li>\n<\/ul>\n<div style=\"text-align: justify\">\n<p>With this method, we write to the <span style=\"font-style: italic\">InternalTag1 <\/span>in the E3 application, as you can see on the previous source code.<\/p>\n<p>So, before clicking the <span style=\"font-style: italic\">writeValueButton<\/span>, set its value and quality in D7 and E7 cells. The timestamp is configured according to the computer&#8217;s clock:<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura10.PNG\" alt=\"\" width=\"550\" height=\"383\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 10:<\/span> <span style=\"font-style: italic\">writeValueButton<\/span>&#8216;s answer<\/span><\/div>\n<p>To confirm that the value was written to the <span style=\"font-style: italic\">InternalTag1<\/span>, use the <span style=\"font-style: italic\">WatchWindow <\/span>tool available on E3 Studio. You can also do this by creating a new button to read the <span style=\"font-style: italic\">InternalTag1<\/span>&#8216;s value.<\/p>\n<p><em><strong><span style=\"color: #ff0000\">Note: Versions 4.5 or higher also feature two new methods: ReadValue and WriteValue. They replace GetValue and SetValue, which henceforth must be avoided.<\/span><\/strong><\/em><\/p>\n<p><span style=\"font-weight: bold\">6) How to receive values with E3DataAccess <\/span><\/p>\n<p>You can also use the E3DataAcccess Library to receive events from the E3 application by using the OnValueChanged event, which receives values in real time, not only at request, like the GetValue method().<\/p>\n<p>So, we will create another button that activates the OnValueChanged event to the <span style=\"font-style: italic\">DemoTag1<\/span>, so its value is sent to a spreadsheet cell when it changes.<\/p>\n<p>Name the button as <span style=\"font-style: italic\">onEventButton <\/span>and set its <span style=\"font-style: italic\">Caption <\/span>property to <span style=\"font-style: italic\">Activate Event<\/span>.\u00a0 Then, access VBA to create a new Class Module by clicking the <span style=\"font-style: italic\">Insert <\/span>menu and selecting the <span style=\"font-style: italic\">Class Module<\/span> option (Figure 11):<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura11.PNG\" alt=\"\" width=\"550\" height=\"399\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 11<\/span>: Inserting a new Class Module via VBA<\/span><\/div>\n<p>Edit the new Class Module&#8217;s name to <span style=\"font-style: italic\">E3ServerEvents <\/span>and insert the following line in its source code:<\/p>\n<pre>Public WithEvents E3EVT As E3DATAACCESSLib.E3DataAccessManager<\/pre>\n<p>With this line, we instance a new <span style=\"font-weight: bold\">E3DataAccess <\/span>object named <span style=\"font-style: italic\">E3EVT <\/span>that can receive events. Then, select the object in the objects&#8217; list box and the <span style=\"font-style: italic\">OnValueChanged <\/span>event in the other list box (Figure 12):<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura12.PNG\" alt=\"\" width=\"550\" height=\"130\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 12<\/span>: VBA&#8217;s objects list box<\/span><\/div>\n<p>By selecting the object, the OnValueChanged is automatically set in the class&#8217; source code:<\/p>\n<pre>Public WithEvents E3EVT As E3DATAACCESSLib.E3DataAccessManager\r\n\r\n'Lines automatically created\r\nPrivate Sub E3EVT_OnValueChanged(ByVal Path As String, ByVal Timestamp As Variant, ByVal Quality As Integer, ByVal Value As Variant)\r\n\r\nEnd Sub<\/pre>\n<p>This event will be generated when data value from the E3 application changes. So, now we will insert the script to be executed when there is a change; configure the spreadsheet cells D10, E10, and F10 to receive the DemoTag1 value, quality, and timestamp, respectively:<\/p>\n<pre>Public WithEvents E3EVT As E3DATAACCESSLib.E3DataAccessManager\r\n\r\n'Created lines\r\nPrivate Sub E3EVT_OnValueChanged(ByVal Path As String, ByVal Timestamp As Variant, ByVal Quality As Integer, ByVal Value As Variant)\r\nRange(\"D10\") = Value\r\nRange(\"E10\") = Quality\r\nRange(\"F10\") = Timestamp\r\n\r\nEnd Sub<\/pre>\n<p>The <span style=\"font-style: italic\">Path <\/span>variable receives the object&#8217;s path that activated the event, which is important when there is more than object being monitored.<\/p>\n<p>After that, instance a new object of the <span style=\"font-style: italic\">E3ServerEvents <\/span>class in the <span style=\"font-style: italic\">E3ServerCom <\/span>Module named as <span style=\"font-style: italic\">E3Evt1<\/span>:<\/p>\n<pre>Public E3Evt1 As New E3ServerEvents 'Created Line\r\nPublic E3 As New E3DATAACCESSLib.E3DataAccessManager<\/pre>\n<p>Now, insert the following source code on the <span style=\"font-style: italic\">onEventsButton<\/span>&#8216;s Click() event:<\/p>\n<pre>Private Sub onEventButton_Click()\r\n   Set E3Evt1.E3EVT = E3\r\n   \r\n   E3.Server = \"E3Server_HostName\"\r\n   \r\n   If Not (E3.RegisterCallback(\"Data.DemoTag1.Value\")) Then\r\n      MsgBox \"It was not possible to register the configured Link!\"\r\n   End If\r\n   \r\nEnd Sub<\/pre>\n<p>In this script, the E3vt1&#8217;s E3EVT property is linked to the instanced E3 object, in order to work with both the E3EVT object and the E3 object. Then, the E3 Server is connected via <span style=\"font-style: italic\">Server <\/span>property.<\/p>\n<p><span style=\"font-weight: bold\">Method RegisterCallback(Link)<\/span><\/p>\n<p>This method is called to monitor events of a certain E3 object. In this example, we will monitor the DemoTag1 object, which has just a single input parameter:<\/p>\n<\/div>\n<ul style=\"text-align: justify\">\n<li>Link &#8211;\u00a0 input parameter that supplies the path of the object to be monitored.<\/li>\n<\/ul>\n<div style=\"text-align: justify\">\n<p>You can monitor more than one object by calling this method for each one of them.<\/p>\n<p>After setting it, it is possible to receive events from <span style=\"font-style: italic\">DemoTag1 <\/span>when clicking the <span style=\"font-style: italic\">Activate Event <\/span>button (Figure 13):<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura13.PNG\" alt=\"\" width=\"550\" height=\"382\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 13<\/span>: Activate Button&#8217;s answer<\/span><\/div>\n<p>Now, we will see how to stop monitoring the <span style=\"font-style: italic\">DemoTag1 <\/span>by using the UnregisterCallback method.<\/p>\n<p><span style=\"font-weight: bold\">Method UnregisterCallback(Link)<\/span><\/p>\n<p>This method also has just a single parameter:<\/p>\n<\/div>\n<ul style=\"text-align: justify\">\n<li>Link &#8211; input parameter that supplies the path of the object to stop monitoring.<\/li>\n<\/ul>\n<div style=\"text-align: justify\">\n<p>When this method is called, it unregisters the E3 application&#8217;s object.<\/p>\n<p>So, create a new button under the <span style=\"font-style: italic\">Activate Event<\/span> button. Edit the new button&#8217;s name to <span style=\"font-style: italic\">offEventButton <\/span>and its <span style=\"font-style: italic\">Caption <\/span>property to <span style=\"font-style: italic\">Deactivate Event<\/span>.<\/p>\n<p>In the <span style=\"font-style: italic\">offEventButton<\/span>&#8216;s Click() event, insert the following script:<\/p>\n<pre>Private Sub offEventButton_Click()\r\n   Set E3Evt1.E3EVT = E3\r\n   \r\n   E3.Server = \"E3Server_HostName\"\r\n   \r\n   If Not (E3.UnregisterCallback(\"Data.DemoTag1.Value\")) Then\r\n      MsgBox \"It was not possible to unregister the set Link!\"\r\n   End If\r\nEnd Sub<\/pre>\n<p>Now, we can activate and deactivate receiving events from <span style=\"font-style: italic\">DemoTag1 <\/span>via <span style=\"font-style: italic\">Activate event<\/span> and <span style=\"font-style: italic\">Deactivate<\/span> <span style=\"font-style: italic\">event <\/span>buttons.<\/p>\n<p><span style=\"font-weight: bold\">7) Performing Queries in the Database object using the E3DataAccess library<\/span><\/p>\n<p>The <span style=\"font-weight: bold\">E3DataAccess <\/span>Library also enables performing Queries in the E3 Database object. To do so, you must create a Database object, configure it, and create a Query object connected to the Database. The E3DataAccess library performs the query using the Query object.<\/p>\n<p>After that, create a new button in the spreadsheet named as <span style=\"font-style: italic\">queryButton<\/span>, set its <span style=\"font-style: italic\">Caption <\/span>property to <span style=\"font-style: italic\">Check DB<\/span>, and insert the following script lines in its Click() event:<\/p>\n<pre>Private Sub queryButton_Click()\r\n   Dim Resposta As Variant\r\n   Dim Names As Variant\r\n   Dim Values As Variant\r\n   Dim rnum As Integer\r\n   \r\n   Answer = Array()\r\n   \r\n   E3.Server = \"E3Server_HostName\"\r\n   \r\n   If E3.GetE3QueryRows(\"Data.Query1\", Names, Values, Answer) Then\r\n      Range(\"G16\") = \"Success!\"\r\n      rnum = 16\r\n      For i = 0 To 20\r\n         Range(\"F\" + CStr(rnum)) = Answer(0, i)\r\n         Range(\"D\" + CStr(rnum)) = Answer (1, i)\r\n         Range(\"E\" + CStr(rnum)) = Answer (2, i)\r\n         rnum = rnum + 1\r\n      Next\r\n   Else\r\n      Range(\"G16\") = \"Fail!\"\r\n   End If\r\nEnd Sub<\/pre>\n<p>This script performs a Query in the Database, and from the spreadsheet cells D16, E16, and F16 on, it fills in the first twenty cells with the results returned by the Query. Remember to connect to the E3 Server before executing the script.<\/p>\n<p><span style=\"font-weight: bold\">NOTE:<\/span> On the example, the Query returns more than twenty records. However, if your Query returns less than twenty records, just edit the For clause according to what you need.<\/p>\n<p><span style=\"font-weight: bold\">Method GetE3QueryRows(Link, Names, Values, Rows)<\/span><\/p>\n<p>By using this method, we perform Queries to the E3 Database. It receives four variables as parameters:<\/p>\n<\/div>\n<ul style=\"text-align: justify\">\n<li><span style=\"font-style: italic\">Link <\/span>&#8211; input parameter that supplies the path of Query object to be executed in the E3 Server.<\/li>\n<li><span style=\"font-style: italic\">Names <\/span>&#8211; input parameter that supplies an array list with variables&#8217; names to be used in the Query&#8217;s execution, if necessary.<\/li>\n<li><span style=\"font-style: italic\">Values <\/span>&#8211; input parameter that supplies an array list with variables&#8217; values returned by the Names parameter to be used in the Query&#8217;s execution, if necessary.<\/li>\n<li><span style=\"font-style: italic\">Rows <\/span>&#8211; output parameter that receives a matrix with the results from the executed Query, if it returns any result.<\/li>\n<\/ul>\n<div style=\"text-align: justify\">\n<p>When calling this method, we refer a Data.Query1 Query by the Link parameter, so, the Query is executed according to its SQL property&#8217;s content. The Names and Values parameters are set with empty lists because there are no variables being used in this Query. The Answer variable will be used only to receive the return of the Query&#8217;s records using the Rows parameter.<\/p>\n<p>The indexes of the returning Answer matrix have the following division:<span style=\"font-style: italic\"> [column][row]<\/span>, the column corresponding to the field and the row to the record returned according to what was requested by the Query. The table consulted in the example has three fields: <span style=\"font-style: italic\">E3TimeStamp<\/span>, <span style=\"font-style: italic\">HisTag <\/span>and <span style=\"font-style: italic\">HisTag_Quality<\/span>. So, the first of the Answer matrix is divided according to the following:<\/p>\n<\/div>\n<ul style=\"text-align: justify\">\n<li>Answer[0][0] &#8211;\u00a0 this is where the value of the <span style=\"font-style: italic\">E3TimeStamp <\/span>field from the first returned record is stored.<\/li>\n<li>Answer [1][0] &#8211; this is where the value of the <span style=\"font-style: italic\">HistTag <\/span>field from the first returned record is stored.<\/li>\n<li>Answer [2][0] &#8211; this is where the value of the <span style=\"font-style: italic\">HisTag_Quality<\/span> field from the first returned record is stored.<\/li>\n<\/ul>\n<div style=\"text-align: justify\">So:<\/div>\n<ul style=\"text-align: justify\">\n<li>Answer[i][j] &#8211; this is where the value of the field i from the row j returned record is stored.<\/li>\n<\/ul>\n<div style=\"text-align: justify\">\n<p>After the source code is ready, when clicking the <span style=\"font-style: italic\">Check DB <\/span>button, we have the following result:<\/p>\n<div style=\"text-align: center\"><img loading=\"lazy\" title=\"\" src=\"https:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura14.PNG\" alt=\"\" width=\"550\" height=\"385\" align=\"bottom\" border=\"0\" \/><br \/>\n<span style=\"font-size: xx-small\"><span style=\"font-weight: bold\">Figure 14<\/span>: Check BD button&#8217;s answer<\/span><\/div>\n<p>After this last step, we have shown all available operations with the <span style=\"font-weight: bold\">E3DataAccess <\/span>Library. With the example application created using VBA, it is possible to read and write values, receive events, and perform queries with E3 application&#8217;s objects.<\/p>\n<p><span style=\"font-weight: bold\">8) Final Remarks<\/span><\/p>\n<p>With this article, we can have a better understanding on how the E3DataAccess Library works. Its functions to work with E3 Server are easy to understand and enable us to perform essential operations on E3 applications.<\/p>\n<p>Besides, it increases the development options for E3 applications and supplies the user with the option to develop applications in known environments.<\/p>\n<h3>Attachments:<\/h3>\n<p><a href=\"\/wp-content\/uploads\/2019\/03\/E3Project-5.zip\">E3Project.zip<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>GENERAL NOTES This article applies to Elipse E3, versions 4.0 or lower. There is a bug when using E3DataAccess library in typeless languages, such as VBScript and JavaScript. This feature&hellip;<\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0},"categories":[826],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Connecting a VBA application to an E3 Server using the E3DataAccess library. - Elipse Knowledgebase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Connecting a VBA application to an E3 Server using the E3DataAccess library.\" \/>\n<meta property=\"og:description\" content=\"GENERAL NOTES This article applies to Elipse E3, versions 4.0 or lower. There is a bug when using E3DataAccess library in typeless languages, such as VBScript and JavaScript. This feature&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/\" \/>\n<meta property=\"og:site_name\" content=\"Elipse Knowledgebase\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/elipsesoftware\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-25T20:37:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-29T13:18:57+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura1.PNG\" \/>\n<meta name=\"author\" content=\"Daniel Seibel Silva\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel Seibel Silva\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"27 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/\"},\"author\":{\"name\":\"Daniel Seibel Silva\",\"@id\":\"https:\/\/kb.elipse.com.br\/#\/schema\/person\/c8f79a90ce0cbb19f4d1c1cdfacdbbc5\"},\"headline\":\"Connecting a VBA application to an E3 Server using the E3DataAccess library.\",\"datePublished\":\"2019-03-25T20:37:39+00:00\",\"dateModified\":\"2022-03-29T13:18:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/\"},\"wordCount\":5117,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/kb.elipse.com.br\/#organization\"},\"articleSection\":[\"E3DataAccess\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/\",\"url\":\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/\",\"name\":\"[:pt]Connecting a VBA application to an E3 Server using the E3DataAccess library.[:en]Connecting a VBA application to an E3 Server using the E3DataAccess library.[:] - Elipse Knowledgebase\",\"isPartOf\":{\"@id\":\"https:\/\/kb.elipse.com.br\/#website\"},\"datePublished\":\"2019-03-25T20:37:39+00:00\",\"dateModified\":\"2022-03-29T13:18:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"In\u00edcio\",\"item\":\"https:\/\/kb.elipse.com.br\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Connecting a VBA application to an E3 Server using the E3DataAccess library.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/kb.elipse.com.br\/#website\",\"url\":\"https:\/\/kb.elipse.com.br\/\",\"name\":\"Elipse Knowledgebase\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/kb.elipse.com.br\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/kb.elipse.com.br\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/kb.elipse.com.br\/#organization\",\"name\":\"Elipse Software\",\"url\":\"https:\/\/kb.elipse.com.br\/\",\"sameAs\":[\"http:\/\/www.facebook.com\/elipsesoftware\"],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/kb.elipse.com.br\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/kb.elipse.com.br\/wp-content\/uploads\/2019\/05\/schererelipse-com-br\/logoElipse.png\",\"contentUrl\":\"https:\/\/kb.elipse.com.br\/wp-content\/uploads\/2019\/05\/schererelipse-com-br\/logoElipse.png\",\"width\":161,\"height\":58,\"caption\":\"Elipse Software\"},\"image\":{\"@id\":\"https:\/\/kb.elipse.com.br\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/kb.elipse.com.br\/#\/schema\/person\/c8f79a90ce0cbb19f4d1c1cdfacdbbc5\",\"name\":\"Daniel Seibel Silva\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/kb.elipse.com.br\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3f74c491a22a7f66a9ab79f1826a1939?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3f74c491a22a7f66a9ab79f1826a1939?s=96&d=mm&r=g\",\"caption\":\"Daniel Seibel Silva\"},\"url\":\"https:\/\/kb.elipse.com.br\/en\/author\/daniel\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Connecting a VBA application to an E3 Server using the E3DataAccess library. - Elipse Knowledgebase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/","og_locale":"en_US","og_type":"article","og_title":"[:pt]Connecting a VBA application to an E3 Server using the E3DataAccess library.[:en]Connecting a VBA application to an E3 Server using the E3DataAccess library.[:] - Elipse Knowledgebase","og_description":"GENERAL NOTES This article applies to Elipse E3, versions 4.0 or lower. There is a bug when using E3DataAccess library in typeless languages, such as VBScript and JavaScript. This feature&hellip;","og_url":"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/","og_site_name":"Elipse Knowledgebase","article_publisher":"http:\/\/www.facebook.com\/elipsesoftware","article_published_time":"2019-03-25T20:37:39+00:00","article_modified_time":"2022-03-29T13:18:57+00:00","og_image":[{"url":"http:\/\/kb.elipse.com.br\/en-us\/images\/ID59\/Figura1.PNG"}],"author":"Daniel Seibel Silva","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Daniel Seibel Silva","Est. reading time":"27 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/#article","isPartOf":{"@id":"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/"},"author":{"name":"Daniel Seibel Silva","@id":"https:\/\/kb.elipse.com.br\/#\/schema\/person\/c8f79a90ce0cbb19f4d1c1cdfacdbbc5"},"headline":"Connecting a VBA application to an E3 Server using the E3DataAccess library.","datePublished":"2019-03-25T20:37:39+00:00","dateModified":"2022-03-29T13:18:57+00:00","mainEntityOfPage":{"@id":"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/"},"wordCount":5117,"commentCount":0,"publisher":{"@id":"https:\/\/kb.elipse.com.br\/#organization"},"articleSection":["E3DataAccess"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/","url":"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/","name":"[:pt]Connecting a VBA application to an E3 Server using the E3DataAccess library.[:en]Connecting a VBA application to an E3 Server using the E3DataAccess library.[:] - Elipse Knowledgebase","isPartOf":{"@id":"https:\/\/kb.elipse.com.br\/#website"},"datePublished":"2019-03-25T20:37:39+00:00","dateModified":"2022-03-29T13:18:57+00:00","breadcrumb":{"@id":"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/kb.elipse.com.br\/en\/connecting-a-vba-application-to-an-e3-server-using-the-e3dataaccess-library\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"In\u00edcio","item":"https:\/\/kb.elipse.com.br\/en\/"},{"@type":"ListItem","position":2,"name":"Connecting a VBA application to an E3 Server using the E3DataAccess library."}]},{"@type":"WebSite","@id":"https:\/\/kb.elipse.com.br\/#website","url":"https:\/\/kb.elipse.com.br\/","name":"Elipse Knowledgebase","description":"","publisher":{"@id":"https:\/\/kb.elipse.com.br\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kb.elipse.com.br\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/kb.elipse.com.br\/#organization","name":"Elipse Software","url":"https:\/\/kb.elipse.com.br\/","sameAs":["http:\/\/www.facebook.com\/elipsesoftware"],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kb.elipse.com.br\/#\/schema\/logo\/image\/","url":"https:\/\/kb.elipse.com.br\/wp-content\/uploads\/2019\/05\/schererelipse-com-br\/logoElipse.png","contentUrl":"https:\/\/kb.elipse.com.br\/wp-content\/uploads\/2019\/05\/schererelipse-com-br\/logoElipse.png","width":161,"height":58,"caption":"Elipse Software"},"image":{"@id":"https:\/\/kb.elipse.com.br\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/kb.elipse.com.br\/#\/schema\/person\/c8f79a90ce0cbb19f4d1c1cdfacdbbc5","name":"Daniel Seibel Silva","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kb.elipse.com.br\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3f74c491a22a7f66a9ab79f1826a1939?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3f74c491a22a7f66a9ab79f1826a1939?s=96&d=mm&r=g","caption":"Daniel Seibel Silva"},"url":"https:\/\/kb.elipse.com.br\/en\/author\/daniel\/"}]}},"_links":{"self":[{"href":"https:\/\/kb.elipse.com.br\/en\/wp-json\/wp\/v2\/posts\/2013"}],"collection":[{"href":"https:\/\/kb.elipse.com.br\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kb.elipse.com.br\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kb.elipse.com.br\/en\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.elipse.com.br\/en\/wp-json\/wp\/v2\/comments?post=2013"}],"version-history":[{"count":7,"href":"https:\/\/kb.elipse.com.br\/en\/wp-json\/wp\/v2\/posts\/2013\/revisions"}],"predecessor-version":[{"id":12845,"href":"https:\/\/kb.elipse.com.br\/en\/wp-json\/wp\/v2\/posts\/2013\/revisions\/12845"}],"wp:attachment":[{"href":"https:\/\/kb.elipse.com.br\/en\/wp-json\/wp\/v2\/media?parent=2013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kb.elipse.com.br\/en\/wp-json\/wp\/v2\/categories?post=2013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kb.elipse.com.br\/en\/wp-json\/wp\/v2\/tags?post=2013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}