Sending data from Excel

Cascade Connect: Version 4.0
Prev | Chapter 5. Tutorial | Next

# 5.3. Sending data from Excel

Sending data from Excel to the data server requires a macro. Once a macro has been created and assigned to a button, sending the data is just a matter of clicking the button and seeing the data arrive on the data server.

| The finished spreadsheet is included in `testfnl.xls` in the Cascade Connect distribution. You can save it as `test.xls` if you want to use it without going through the steps to create it.

## 5.3.1. Create a macro

1. Open the `test.xls` spreadsheet you created in the previous part of the tutorial.

2. From the Tools menu, select Macro, and then Macros....

3. In the Macro Name: field of the Macro dialog box, type the name `SendOutput`, and press the Create button.

4. In the Visual Basic text entry window that comes up, edit the macro to read as follows:

           '
           ' SendOutput Macro
           '
           Sub SendOutput()
               mychannel = DDEInitiate("cascade", "data")
               Application.Worksheets("Sheet1").Activate
               Call DDEPoke(mychannel, "output1", Cells(4, 3))
               DDETerminate mychannel
           End Sub

5. Save and close the Visual Basic text entry window.

## 5.3.2. Complete the spreadsheet

Follow these steps in `test.xls`:

1. Type the text `Output =>` into cell B4 and right justify it.

2. Change the name of cell C4 to output1.

3. Activate the Forms toolbar by clicking on the View menu and selecting Toolbars, and then Forms.

4. Click on the button icon, and then click in cell D4. An Assign Macro window should appear.

5. Select SendOutput and click OK.

6. Change the label on the button to "Send".

7. For appearance, you can move the button, resize it with the handles, and change the size of the text by right-clicking on it and selecting Format Control.

8. Save `test.xls` and exit.

## 5.3.3. Send the data

To see the data arrive on the data server, you will need to start the cascwait program there. That program 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:

           [sh]$ cascwait

2. Now you're ready to send the data. In Windows, double click on the Excel Test icon you have created.

3. Type a number (for example `24`) in cell C4 and press Enter.

4. Click the Send button.

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

           Received message: (point output1 2  24)

   This indicates that Excel data is being sent to the data server.

Prev | Home | Next
Receiving data in Excel | Up | Incorporating the Cascade DataHub

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