如何插入iFIX动态数据到Excel工作 下载本文

内容发布更新时间 : 2024/5/19 22:57:34星期一 下面是文章的全部内容请认真阅读。

写IFIX实时数据到Excel 2007-02-28 11:22 Description

Inserting FIX Dynamics data into an Excel worksheet.

Resolution

The following procedure will enable you to insert FIX Dynamics data into an Excel worksheet:

// Declare necessary API routines:

Private Declare Function FindWindow Lib \\ByVal lpWindowName As Long) As Long

Private Declare Function SendMessage Lib \\ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Sub DetectExcel()

// Procedure dectects a running Excel and registers it. Const WM_USER = 1024 Dim hwnd As Long

// If Excel is running this API call returns its handle. hwnd = FindWindow(\

If hwnd = 0 Then // 0 means Excel not running. Exit Sub Else

// Excel is running so use the SendMessage API

// function to enter it in the Running Object Table. SendMessage hwnd, WM_USER + 18, 0, 0 End If End Sub

Private Sub CommandButton2_Click()

Dim msexcel As Excel.Application

Set msexcel = CreateObject(\With msexcel .Visible = True

.Workbooks.Open \End With

End Sub

Private Sub CommandButton3_Click()

Dim MyXL As Object // Variable to hold reference to Microsoft Excel. Dim ExcelWasNotRunning As Boolean // Flag for final release.

// Test to see if there is a copy of Microsoft Excel already running. On Error Resume Next // Defer error trapping.

// Getobject function called without the first argument returns a // reference to an instance of the application. If the application isn//t

// running, an error occurs. Note the comma used as the first argument

// placeholder.

Set MyXL = GetObject(, \

If Err.Number <> 0 Then ExcelWasNotRunning = True

Err.Clear // Clear Err object in case error occurred. // Check for Excel. If Excel is running, // enter it into the Running Object table. DetectExcel

//Set the object variable to reference the file you want to see. Set MyXL = GetObject(\

// Show Microsoft Excel through its Application property. Then // show the actual window containing the file using the Windows // collection of the MyXL object reference. MyXL.Application.Visible = True

MyXL.Parent.Windows(1).Visible = True

// Do manipulations of your file here. With MyXL.Application

.ActiveWorkbook.ActiveSheet.Select .Goto reference:=.Range(\

.Selection = Fix32.Johnski2.AI1.F_CV End With

// If this copy of Microsoft Excel was not already running when you // started, close it using the Application property//s Quit method. // Note that when you try to quit Microsoft Excel, the Microsoft Excel

// title bar blinks and Microsoft Excel displays a message asking if you

// want to save any loaded files.

If ExcelWasNotRunning = True Then MyXL.Application.Quit End If

Set MyXL = Nothing // Release reference to the application and spreadsheet. End Sub

6:iFIX_如何使用脚本实现驱动(7x)的启动和停止? Description

The following solution explains how to Start and Stop a 7.x driver through VBA code. This example uses

the ABR driver. To implement this with another 7.x driver, change the ABR to the three letter acronym of

the other driver and switch the reference to that driver.

Resolution

This code will only work with 7.x drivers. If you want to implement this is code in a new picture you

need to set a reference to Intellution ABRDrv OPC Server 7.20 Library. To set a reference, use the following steps:

1) On the Tools menu in the VB Editor choose References.

2) Select the Intellution ABRDrv OPC Server 7.20 Library from the list.

Add two command buttons to your picture and name them cmdStart_Click and cmdStop_Click.