Chapter 7. Connecting to Excel

Table of Contents
7.1. Preliminary check: sending data between Excel and the data server
7.2. Displaying data server data in an Excel spreadsheet
7.3. Using Remote Reference Formulas
7.4. Multiple Cell References
7.5. Tips for Writing Reports in Excel
7.6. Creating write-backs from Excel to the data server
7.7. The system variable

Cascade Connect has been used extensively with Microsoft Excel. There are a few different ways to link Excel to Cascade Connect, and to Cascade DataHub points.

7.1. Preliminary check: sending data between Excel and the data server

Here's a way to set up and confirm message passing between Excel and the data server via Cascade Connect.

7.1.1. Windows configuration

7.1.1.1. Create a Cascade Connect configuration file for Excel

To create the configuration file follow these steps:

  1. In Windows, open the Cascade Connect Setup window by clicking on the icon in the Cascade Connect group.

  2. Click on the Excel button to complete most of the settings you will require.

  3. Change the contents of the Program to Launch field to match the path to Excel on your computer. You can use the button to find the location of excel.exe on your computer.

  4. Notice that the Program Argument displays the name an Excel file, test.xls. This is an example spreadsheet we have provided to demonstrate the link between the data server and Excel. You should ensure that the path is correct, using the button to verify the path names.

  5. Select Debug Mode.

  6. Delete the myhost.mydomain.com text in the Server IP Addresses name entry field and replace it with the name of your data server computer. Then click the Add button.

  7. Notice that the DDE and Name Settings have been configured for you, as shown below:

  8. You should change the TCP Heartbeat to 10,000 msec.

  9. And also change the TCP Timeout to 50,000 msec. These two settings will slow down the heartbeat sent between the data server and Windows, allowing you to read the messages as they are sent between Cascade Connect and the Connect Server.

  10. Save the file as

        c:\shortened_path_to_executable\excel.ini

    where shortened_path_to_executable is the path notation used by DOS (8 characters per file or folder name) of the path where Cascade Connect is installed on your machine. For example, the default installation path is c:\progra~1\cogent\cascad~1\.

7.1.1.2. Configuring a shortcut icon

To initiate the Cascade Connect program we must define a shortcut link in Windows. To do this, follow these instructions:

  1. Copy one of the icons that are already displayed in the Cascade Connect Windows group.

  2. Rename the icon to something like Excel Test.

  3. Right click on the icon and display the properties.

  4. Ensure that the Target field reads:

        "C:\path_to_executable\cascade.exe" -i excel.ini

    where path_to_executable is the complete form of the directory path to where Cascade Connect is installed on your machine. For example, the default installation path is "C:\Program Files\Cogent\Cascade Connect". If the entry is not correct, edit it.

  5. Ensure that the Start in field reads:

        "C:\path_to_executable"

    where path_to_executable is the same as above. If the entry is not correct, edit it.

  6. Save the new icon properties.

7.1.1.3. The Excel demo spreadsheet

The Excel demo spreadsheet we have provided is quite simple, containing one Visual Basic macro attached to a button. This macro reads the number in one of the cells of the spreadsheet and sends the number to Cascade Connect. We will use the Excel demo spreadsheet to view information sent from the data server, and also to send data to the data server. On the data server, we will use a program called cascwait to display any messages sent from the Excel spreadsheet.

To run Cascade Connect using the Excel demo spreadsheet, follow these instructions:

  1. Double click on the shortcut icon you created called Excel Test.

  2. Cascade Connect will start and immediately activate Excel. Excel will load the demo spreadsheet, and the Cascade Connect runtime window will stay visible to show you debug information. Resize and reposition the Excel window so that you can see both the spreadsheet and the Cascade Connect runtime window.

  3. Excel will display a screen similar to this:

  4. The TCP LINK field shows that the Cascade Connect link to the data server has been established. The DATABASE field shows that Cascade Connect has not established a link to a Cascade DataHub on the data server. If we had defined a datahub domain and started a datahub on the data server, this field would display 1 when the connection was made.

7.1.1.4. Sending data server data to the Excel demo

To send data server data to the Excel demo, follow these instructions:

  1. Using a console on the data server or a telnet session from Windows, type the following command at the command prompt:

        demowrite 500
  2. In the Excel spreadsheet you should see the input1 field update as the data server data arrives. You may notice that the update of this information is slower in Excel than it was when we were simply watching the data arrive in Cascade Connect. This is because Excel has to work hard to update the screen each time a value arrives and this slows down the connection. In all cases we have tested, the Windows client program is the slowest link in the connection, and Cascade Connect will always be faster than the Windows client can accommodate.

7.1.1.5. Sending Excel data to the data server

On the data server we have to start the cascwait program, which acts as the data server client and displays messages it receives to the standard output.

  1. Using a console on the data server or a telnet session from Windows, type the following command at the command prompt:

        cascwait
  2. Now enter a number (for example 24) into the output1 cell in the Excel spreadsheet and press Enter (to have Excel accept the number you typed).

  3. Then click the Send Data button to run the Excel macro that actually sends the DDE message to Cascade Connect.

  4. On the data server you should see the following message:

        Received message: (point output1 2  24 )

    This indicates that Windows data is being sent to the data server by Cascade Connect.

7.1.1.6. What if I don't get these results?

Important

If you find that the cascwait program does not display a message on the data server when you send data from Excel then you should check the following:

  • Check that the Allow Advise option has been selected in the Program Launch Options of the Cascade Connect Setup window. Cascade Connect uses DDE POKE commands to send data server data to Excel, and accepts DDE ADVISE commands to receive Excel data for the data server.

  • Make sure you have started cascwait on the data server.

  • On the data server, check to see if the Cascade NameServer program (nserve) is running. This program is typically started after the Cascade QueueServer program (qserve) and used in conjunction with the Cascade DataHub. If nserve is running, the Connect Server is waiting to connect to a Cascade DataHub (even though you may not have given any datahub information in the Setup window). Cascade Connect performs a check when it starts the Connect Server to see if it can find a Cascade DataHub to attach to. If it identifies a name server (ie. nserve), then it assumes that a Cascade DataHub will be available soon and will not send data to any other data server task (even if you define a Server client Name in the Setup window).

    If you have nserve running on the data server then you will have probably have access to the Cascade DataHub. In any case, the solution to the problem is to either slay the nserve task on the data server, or start a Cascade DataHub. If you choose to start a Cascade DataHub, you will need to use a Cogent program called waiter in place of the cascwait program. waiter is a program that receives all messages from the Cascade DataHub and displays summary information to the standard output.

  • Check the syntax of the Excel macro. This macro is described in Creating write-backs from Excel to the data server.

Note

You can speed up the transmission of data to the Windows client by turning off debug information in the Cascade Connect configuration file.

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.